I’m trying to parse a JSON string using the json library. This code works perfectly in GHCI:
import Text.JSON as JS
JS.decode "{}" :: Result JSValue
But when I use the same code in a compiled program:
case JS.decode "{}" of
JS.Ok value -> putStrLn value
JS.Error err -> error err
It is unable to parse the String with:
Unable to read String
I suspect it’s just me doing something stupid but I can’t figure out what….
Any ideas very very welcome!
Update:
I wrote this code to see if it was something in the other part of the app causing the problem:
import qualified Text.JSON as JS
main :: IO ()
main = do
case JS.decode "{}" of
JS.Ok value -> putStrLn value
JS.Error err -> error err
However I get the same error with this:
test: Unable to read String
It’s compiled with GHC 7.0.3 and the source was edited with vim. However even string data passed in from outside the app generate the same error. Really out of ideas now…
Use
printinstead ofputStrLn, which only works on Strings: