[Haskell] I'm a beginner --- struggling with the SimpleJSON example from Real World Haskell

dhjdhj dhjdhj at gmail.com
Tue Dec 14 22:28:50 CET 2010




I'm sure this question has been asked many times but I have not been able to
find it anywhere.


I have written the code below into Lekseh directly from the RWH book.
However, I always get the error

   parse error on input 'getString' and the line number refers to the type
declaration for getString.

I have no idea what's wrong and would appreciate any suggestions to get past
this.

Thanks in advance

David
----------------------------



module SimpleJSON (

   JValue(..),
   getString,
   getInt,
   getDouble,
   getBool,
   getObject,
   getArray,
   isNull
)

where



   data JValue = JString String
            | JNumber Double
            | JBool Bool
            | JNull
            | JObject [ (String, JValue) ]
            | JArray [JValue]

      deriving (Eq, Ord, Show)


getString :: JValue -> Maybe String
getString (JString s) = Just s
getString _           = Nothing

getInt (JNumber n)    = Just (truncate n)
getInt _              = Nothing

getDouble (JNumber n) = Just n
getDouble _           = Nothing

getBool (JBool b)     = Just b
getBool _             = Nothing

getObject (JObject o) = Just o
getObject _           = Nothing

getArray (JArray a)   = Just a
getArray _            = Nothing

isNull v              = v == JNull



-- 
View this message in context: http://haskell.1045720.n5.nabble.com/I-m-a-beginner-struggling-with-the-SimpleJSON-example-from-Real-World-Haskell-tp3305331p3305331.html
Sent from the Haskell - Haskell mailing list archive at Nabble.com.



More information about the Haskell mailing list