Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Added generic instance for Unit #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Data/Generic.purs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ isValidSpine (SigRecord fieldSigs) (SRecord fieldVals) =
(sortBy (\a b -> compare a.recLabel b.recLabel) fieldVals)
isValidSpine _ _ = false


instance genericUnit :: Generic Unit where
toSpine _ = SProd "Prelude.Unit" []
toSignature _ = SigProd "Prelude.Unit" [{ sigConstructor : "Prelude.Unit"
, sigValues : []
}]
fromSpine (SProd "Prelude.Unit" []) = Just unit
fromSpine _ = Nothing

instance genericNumber :: Generic Number where
toSpine x = SNumber x
toSignature _ = SigNumber
Expand Down
1 change: 1 addition & 0 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ main = do
, Corge ['H', 'i', ' ', 'D', 'e', 'r', 'e'] ]

log "Testing Show GenericSignature instance:"
print (toSignature (Proxy :: Proxy Unit))
print (toSignature (Proxy :: Proxy Number))
print (toSignature (Proxy :: Proxy Char))
print (toSignature (Proxy :: Proxy (Array (Array Number))))
Expand Down