Hello! I'm observing a strange type inference result in the program at the end of the message. term1 and term2 have the same definitions, except for a type annotation for term2, but GHCi infers the following types: *Main> :t term1 term1 :: Term () *Main> :t term2 term2 :: forall a. Term a Could anyone please explain this? Thank you, / Emil ----------------------------------- data Term a = X class Constructive term a | term -> a where construct :: term -> Term a instance Constructive (Term a) a where construct = id term1 = construct X term2 :: Term a term2 = construct X
On 7/7/06, Emil Axelsson <emax@cs.chalmers.se> wrote:
Hello!
I'm observing a strange type inference result in the program at the end of the message.
term1 and term2 have the same definitions, except for a type annotation for term2, but GHCi infers the following types:
*Main> :t term1 term1 :: Term () *Main> :t term2 term2 :: forall a. Term a
Could anyone please explain this?
It's because of the monomorphism restriction which is widely regarded as one of the uglier parts of Haskell. You can turn it off with -fno-monomorphism-restriction and read more about it here: http://haskell.org/onlinereport/decls.html#sect4.5.5 -- Friendly, Lemmih
participants (2)
-
Emil Axelsson -
Lemmih