[Haskell-cafe] What monad am I in?
Jonathan Cast
jonathanccast at fastmail.fm
Tue Sep 2 19:50:17 EDT 2008
On Tue, 2008-09-02 at 20:25 +0000, 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?
Yes. This is a peculiarity of GHCi (and ghc -e) --- IO actions at
top-level are executed by default, while non-IO values are simply
printed out.
jcc
More information about the Haskell-Cafe
mailing list