
26 Jul
2010
26 Jul
'10
9:50 a.m.
How about: *Main> fromJValue (JBool True) :: Either JSONError Bool Right True *Main> Doaitse On 26 jul 2010, at 15:16, Angel de Vicente wrote:
data JValue = JString String | JNumber Double | JBool Bool | JNull | JObject [(String, JValue)] | JArray [JValue] deriving (Eq, Ord, Show)
type JSONError = String
class JSON a where toJValue :: a -> JValue fromJValue :: JValue -> Either JSONError a
instance JSON JValue where toJValue = id fromJValue = Right
instance JSON Bool where toJValue = JBool fromJValue (JBool b) = Right b fromJValue _ = Left "not a JSON boolean"