[Haskell-beginners] How do ambigious types compile with Aeson

Sevcsik András sevcsik at gmail.com
Sun Sep 13 01:15:43 UTC 2015


Hi list,

> ghci> decode $ fromStrict $ encodeUtf8 $ "{\"a\" : \"b\"}"
> Nothing

> ghci> decode $ fromStrict $ encodeUtf8 $ "{\"a\" : \"b\"}" :: Maybe Object
> Just (fromList [("a",String "b")])

The question is: how can the first example compile? I would expect that
since GHC cannot infer the type I want from Aeson to decode to, it would
die with an error that "t0 type variable is ambigious". But instead, it
compiles just fine, and fails runtime.

How it's decided what type should Aeson try to decode to? What type is that
gives me Nothing on whatever JSON input I give?

Cheers,
Andras Sevcsik

-- 
Minden jót,
Sevcsik András
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150913/f8c03668/attachment.html>


More information about the Beginners mailing list