
On Tue, Sep 2, 2008 at 5:33 PM, Ryan Ingram
ghci has some crazy defaulting rules for expressions at the top level.
In particular, it tries to unify those expressions with a few different types, including IO.
On the other hand, the let-expression is typed like regular Haskell and you run into the monomorphism restriction.
Right. Just to make it clear for the original poster, this monomorphism restriction is not about GHCi specifically, just GHC in general. With the -fno-monomorphism-restriction, you will not get this error.
-- ryan
On Tue, Sep 2, 2008 at 1:25 PM, Henry Laxen
wrote: Dear Group,
When I fire up ghci and define:
increment x = return (x+1)
I can say: Main> increment 1
and ghci dutifully replies 2. Also as expected, the type signature of increment is: (Num a, Monad m) => a -> m a
However, if I say:
Main> let a = increment 1
I get:
<interactive>:1:8: Ambiguous type variable `m' in the constraint: `Monad m' arising from a use of `increment' at <interactive>:1:8-18 Probable fix: add a type signature that fixes these type variable(s)
Have I, like Monsier Jourdain, been running in the IO monad all my life, and didn't even know it?
Thanks, Henry Laxen
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe