[Haskell-beginners] Re: question about show -- RWH chapter 5

7stud bbxx789_05ss at yahoo.com
Thu Mar 26 12:04:19 EDT 2009

Peter Verswyvelen <bugfact <at> gmail.com> writes:
> Well, for JSON, I think the rendered string must be enclosed in double quotes, 
> which is what the show instance for String does.

Ahh.  I see.  My version yields this output:

main = let x = JString "hello" 
           y = JNumber 10
           rx = renderJValue x
           ry = renderJValue y
       in putStrLn ("[" ++ rx ++ ", " ++ ry ++ "]")

$ simple
[hello, 10.0]

...and that is not correct JSON format. hello looks like a variable 
name--not a string.  The books version produces:

["hello", 10.0]

which is what a javascript array that contains a string looks like.


More information about the Beginners mailing list