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]
[6,7,8,9,6,7,8,9,6,7,8,9]
That is, it just repeats the second argument as many times as the
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
Before somebody noticed: I'm wrong.
It's not List monad, but also a (-) x monad, also defined in
Control.Monad.
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
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].
Actually, it seems that in this case return is from the ((-) a) monad,
i.e. return=const.
f x y = x = return y
= x = const y
= (concat . map)
Am Mittwoch, 16. April 2008 14:56 schrieb Hans Aberg:
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]
[6,7,8,9,6,7,8,9,6,7,8,9]
That
On 16 Apr 2008, at 15:22, Daniel Fischer wrote:
The point is the
instance Monad ((-) a) where
return x = const x
f = g = \x - g (f x) x
which is defined in Control.Monad.Instances...
Thank you. I suspected there was an instance somewhere, and I wanted
to know where it is defined.
On 16 Apr 2008, at 15:14, Miguel Mitrofanov wrote:
Before somebody noticed: I'm wrong.
It's not List monad, but also a (-) x monad, also defined in
Control.Monad.
Therefore, return y is just const y. Therefore,
x = (return y) = x = (const y) = x y
Right. It is an interesting monad, but