[Haskell-beginners] exception, not in IO

Kees Bleijenberg k.bleijenberg at lijbrandt.nl
Tue Jul 16 10:04:41 CEST 2013


We discover that this function is pretty simple in fact and combine some pure code that does provide pure exceptions, so defining a new function may bring a solution :

tryDecodingJSON :: (Data a) => String -> Result a tryDecodingJSON s =
    case runGetJSON readJSValue s of
    Left msg -> Error msg
    Right j -> fromJSON j

You may need to import Text.JSON.String for runGetJSON.
This is a nice solution for the problem. 


More information about the Beginners mailing list