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

David Jameson dhjdhj at gmail.com
Tue Dec 14 22:44:23 CET 2010


OMG --- that was it --- I can't tell you how many hours I have been wrestling with this.

Thank you so much for the quick response.

I was aware that Haskell required indentation for some things (and I'm a fan of indentation) but I didn't realize it required NO indentation for some things --- I thought that went away with FORTRAN  (grin)

D

On Dec 14, 2010, at 4:37 PM, Patrick LeBoutillier wrote:

> Hi,
> 
> Make sure the line
> 
>  data JValue ...
> 
> is not indented. I should start at the first column.
> 
> 
> Patrick
> 
> 
> On Tue, Dec 14, 2010 at 4:28 PM, dhjdhj <dhjdhj at gmail.com> wrote:
>> 
>> 
>> 
>> 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.
>> 
>> _______________________________________________
>> Haskell mailing list
>> Haskell at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell
>> 
> 
> 
> 
> -- 
> =====================
> Patrick LeBoutillier
> Rosemère, Québec, Canada
> 




More information about the Haskell mailing list