@@ -22,14 +22,19 @@ import Data.String (joinWith)
22
22
data GenericSpine = SProd String (Array (Unit -> GenericSpine ))
23
23
| SRecord (Array { recLabel :: String , recValue :: Unit -> GenericSpine } )
24
24
| SNumber Number
25
+ | SBoolean Boolean
25
26
| SInt Int
26
27
| SString String
27
28
| SArray (Array (Unit -> GenericSpine ))
28
29
29
30
-- | A GenericSignature is a universal representation of the structure of an arbitrary data structure (that does not contain function arrows).
30
31
data GenericSignature = SigProd (Array { sigConstructor :: String , sigValues :: Array (Unit -> GenericSignature )} )
31
32
| SigRecord (Array { recLabel :: String , recValue :: Unit -> GenericSignature } )
32
- | SigNumber | SigInt | SigString | SigArray (Unit -> GenericSignature )
33
+ | SigNumber
34
+ | SigBoolean
35
+ | SigInt
36
+ | SigString
37
+ | SigArray (Unit -> GenericSignature )
33
38
34
39
-- | A proxy is a simple placeholder data type to allow us to pass type-level data at runtime.
35
40
data Proxy a = Proxy
@@ -63,12 +68,9 @@ instance genericString :: Generic String where
63
68
fromSpine _ = Nothing
64
69
65
70
instance genericBool :: Generic Boolean where
66
- toSpine true = SProd " true" []
67
- toSpine false = SProd " false" []
68
- toSignature _ = SigProd [{sigConstructor: " true" ,sigValues: [] },
69
- {sigConstructor: " false" ,sigValues: []}]
70
- fromSpine (SProd " true" [] ) = Just true
71
- fromSpine (SProd " false" [] ) = Just false
71
+ toSpine b = SBoolean b
72
+ toSignature _ = SigBoolean
73
+ fromSpine (SBoolean b) = Just b
72
74
fromSpine _ = Nothing
73
75
74
76
instance genericArray :: (Generic a ) => Generic (Array a ) where
@@ -127,11 +129,11 @@ genericShowPrec d (SProd s arr) =
127
129
showParen true x = " (" <> x <> " )"
128
130
129
131
genericShowPrec d (SRecord xs) = " {" <> joinWith " , " (map (\x -> x.recLabel <> " : " <> genericShowPrec 0 (x.recValue unit)) xs) <> " }"
130
-
131
- genericShowPrec d (SInt x) = show x
132
- genericShowPrec d (SNumber x) = show x
133
- genericShowPrec d (SString x) = show x
134
- genericShowPrec d (SArray xs) = " [" <> joinWith " , " (map (\x -> genericShowPrec 0 (x unit)) xs) <> " ]"
132
+ genericShowPrec d ( SBoolean x) = show x
133
+ genericShowPrec d (SInt x) = show x
134
+ genericShowPrec d (SNumber x) = show x
135
+ genericShowPrec d (SString x) = show x
136
+ genericShowPrec d (SArray xs) = " [" <> joinWith " , " (map (\x -> genericShowPrec 0 (x unit)) xs) <> " ]"
135
137
136
138
-- | This function can be used as the default instance for Show for any instance of Generic
137
139
gShow :: forall a . (Generic a ) => a -> String
@@ -145,10 +147,11 @@ instance eqGeneric :: Eq GenericSpine where
145
147
&& zipAll (\x y -> x unit == y unit) arr1 arr2
146
148
eq (SRecord xs) (SRecord ys) = length xs == length ys && zipAll go xs ys
147
149
where go x y = x.recLabel == y.recLabel && x.recValue unit == y.recValue unit
148
- eq (SInt x) (SInt y) = x == y
149
- eq (SNumber x) (SNumber y) = x == y
150
- eq (SString x) (SString y) = x == y
151
- eq (SArray xs) (SArray ys) = length xs == length ys && zipAll (\x y -> x unit == y unit) xs ys
150
+ eq (SInt x) (SInt y) = x == y
151
+ eq (SNumber x) (SNumber y) = x == y
152
+ eq (SBoolean x) (SBoolean y) = x == y
153
+ eq (SString x) (SString y) = x == y
154
+ eq (SArray xs) (SArray ys) = length xs == length ys && zipAll (\x y -> x unit == y unit) xs ys
152
155
eq _ _ = false
153
156
154
157
-- | This function can be used as the default instance for Eq for any instance of Generic
@@ -180,6 +183,9 @@ instance ordGeneric :: Ord GenericSpine where
180
183
compare (SInt x) (SInt y) = compare x y
181
184
compare (SInt _) _ = LT
182
185
compare _ (SInt _) = GT
186
+ compare (SBoolean x) (SBoolean y) = compare x y
187
+ compare (SBoolean _) _ = LT
188
+ compare _ (SBoolean _) = GT
183
189
compare (SNumber x) (SNumber y) = compare x y
184
190
compare (SNumber _) _ = LT
185
191
compare _ (SNumber _) = GT
0 commit comments