How do ambigious types compile with Aeson

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

On Sat, Sep 12, 2015 at 9:15 PM, Sevcsik András
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?
ghci has ExtendedDefaultRules enabled, which means that many things will infer a type of () if one cannot otherwise be determined. This is not something Aeson has control over. Try ":seti -XNoExtendedDefaultRules" and ask ghci again; it should produce an ambiguous type error. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

That explains it, thank you!
On Sun, Sep 13, 2015, 03:20 Brandon Allbery
On Sat, Sep 12, 2015 at 9:15 PM, Sevcsik András
wrote: 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?
ghci has ExtendedDefaultRules enabled, which means that many things will infer a type of () if one cannot otherwise be determined. This is not something Aeson has control over. Try ":seti -XNoExtendedDefaultRules" and ask ghci again; it should produce an ambiguous type error.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Minden jót, Sevcsik András
participants (2)
-
Brandon Allbery
-
Sevcsik András