[Haskell-cafe] Funny State monad dependency
miguelimo38 at yandex.ru
Wed Apr 16 09:14:14 EDT 2008
Before somebody noticed: I'm wrong.
It's not List monad, but also a "(->) x" monad, also defined in
Therefore, "return y" is just "const y". Therefore,
x >>= (return y) = x >>= (const y) = x >> y
On 16 Apr 2008, at 17:04, Miguel Mitrofanov wrote:
> It has nothing to do with State; it actually works in List monad.
> "return y" is just another way of writing "[y]".
> You don't need to import Control.Monad.State for this to work; you
> only need Control.Monad (which is imported by the former).
> On 16 Apr 2008, at 16:56, Hans Aberg wrote:
>> When I load the State module in Hugs, then I can define the
>> function f below, but I do not immediately see exactly what
>> function "return" returns. Explanation welcome.
>> For example:
>> > f [2..4] [6..9]
>> That is, it just repeats the second argument as many times as the
>> length of the second argument.
>> Hans Aberg
>> import Control.Monad.State
>> f :: Monad a => a b -> a c -> a c
>> f x y = x >>= (return y)
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe