[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] What monad am I in?

Subject: Re: [Haskell-cafe] What monad am I in?
From: "Philip Weaver"
Date: Tue, 2 Sep 2008 18:49:44 -0700


On Tue, Sep 2, 2008 at 5:33 PM, Ryan Ingram <[email protected]> wrote:
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 <[email protected]> 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
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe
<Prev in Thread] Current Thread [Next in Thread>