[Haskell-beginners] in which monad am I?
Rahul Kapoor
rk at trie.org
Sun Jan 3 17:06:27 EST 2010
I am not sure I completely understand your question (I think I do)
> But doesn't ever happen that poor liftM be confused?
The compiler is able to figure out which Monad you are working in
via type inference. This is true for all overloaded functions not
just the monadic ones. For example in this ghci session:
Prelude> :m Control.Monad
Prelude Control.Monad> liftM id [1]
[1]
Prelude Control.Monad> liftM id (Just "qaz")
Just "qaz"
ghci is able to infer that the Monad's in question are the Maybe and
List respectively.
In (almost?) all cases type inference allows the compiler to pick
which overloaded
implementation is to be used.
>and do poor
> haskell programmers never feel the need to explicitly state to which
> monad they "wish to lift" ?
It is probably a matter of taste - but adding type signatures even in
the presence
of type inference is usually a good thing except for the most trivial cases It
serves as a documentation and a quick test by making sure that the
compiler and you
infer the same type since it is a compile error to specify a type
which is not compatible
with what the compiler infers.
The haskell wiki book though incomplete in places does a good job and
so does the
wikipedia entry for Type Inference
http://en.wikibooks.org/wiki/Haskell/Type_basics#Type_inference
http://en.wikipedia.org/wiki/Type_inference
http://stackoverflow.com/questions/463870/when-to-exploit-type-inference-in-haskell
On Sun, Jan 3, 2010 at 4:38 PM, Francesco Guerrieri
<f.guerrieri at gmail.com> wrote:
> Hello, this is my first post to the list.
>
> I am learning Haskell and I think I understand monads (well, that
> doesn't mean that I actually understand them :-) )
> Nevertheless, I would like to check something with you.
> My question is: how do you know in which monad you are computing at a
> given time?
> What I mean is that, when dealing with more than a monad at the same
> time (Maybe, List, IO come to my mind) if I understand correctly you
> have to lift values back and forth from a monad to the other. How do
> you "keep" track of the monad you are in a given time? I think that
> the type system will help to resolve to the relevant function (eg,
> thinking to liftM signature, liftM :: (Monad m) => (a1 -> r) -> m a1
> -> m r
>
> But doesn't ever happen that poor liftM be confused? and do poor
> haskell programmers never feel the need to explicitly state to which
> monad they "wish to lift" ?
>
> I hope it's not a too silly question. If so, please point me to the
> relevant resouces (Are monad transformers relevant to my issue?)
>
> Thanks in advance,
> Francesco
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
More information about the Beginners
mailing list