I am trying to use the show function and get back output that looks like JSON The type I have to work with is
data JSON = JNum Double
| JStr String
I am looking for
JNum 12, JStr"bye", JNum 9, JStr"hi" to return
[12, "bye", 9, "hi"]
I have attempted:
instance Show JSON where
show ans = "[" ++ ans ++ "]"
but fails with a compile error. I have also tried
instance Show JSON where
show ans = "[" ++ ans ++ intercalate ", " ++ "]"
but failed with "Not in scope: data constructor 'JSON' Not sure how to use "ans" to represent whatever type JSON receives as input in the ouput, be it a string, double..etc... Not very good with Haskell so any hints would be great.
Thx for reading