This expression is incorrect.
f = show
However, in ghci this is legit
let f = show
Moreover, its type is changed to
() -> String
Is there any explanation of this phenomenon?
The ghci prompt behaves as if the ExtendedDefaultRules extension is enabled.
ExtendedDefaultRules
In particular this means that:
The unit type () is added to the start of the standard list of types which are tried when doing type defaulting.
So to get the same behaviour from a source file, either compile with -XExtendedDefaultRules, or add {-# LANGUAGE ExtendedDefaultRules #-} to the top of the file.
-XExtendedDefaultRules
{-# LANGUAGE ExtendedDefaultRules #-}
1.4m articles
1.4m replys
5 comments
57.0k users