For the sake of approaching this in yet another way, it can also be helpful
to substitute the definitions of bind and return in your expression. If we
start with the definitions:
instance Monad [] where
xs >>= f = concat (map f xs)
return x = [x]
Then we can make the following transformations
Matt
It is not return, but the bind the one that does the miracle of
multiplication.
By its definition for the list monad, it applies the second term once for
each element are in the first term.
So return is called many times. At the end, bind concat all the small
lists generated
2013/7/20 Matt
Hi,
Thanks all for your good help. I was caught up in sequential thinking about
monads so much so that I treated the lambda expressions as separate functions
rather than a nested big one.
That clears up a lot of nagging doubts.
Cheers,
Matt.
On 20 Jul 2013, at 00:18, Rogan Creswick wro
On 07/20/2013 12:58 AM, Matt Ford wrote:
Hi,
Thanks for the help.
I thought >>= was left associative? It seems to be in the examples from
Learn You A Haskell.
...
Yes, >>= is left-associative. The associativity of >>= is not relevant
for your example because no two >>= operations actually o
> I thought >>= was left associative? It seems to be in the examples from
> Learn You A Haskell.
It is. But lambdas are parsed using the "maximal munch" rule, so they
extend *as far to the right as possible*.
So
\x -> x * 2 + 1
would be parsed as
\x -> (x * 2 + 1) -- right
not
On Fri, Jul 19, 2013 at 3:58 PM, Matt Ford wrote:
> Hi,
>
> Thanks for the help.
>
> I thought >>= was left associative? It seems to be in the examples from
> Learn You A Haskell.
>
> I tried to use the associative law to bracket from the right but it didn't
> like that either...
>
> [1,2] >>= (
Hi,
Thanks for the help.
I thought >>= was left associative? It seems to be in the examples from Learn
You A Haskell.
I tried to use the associative law to bracket from the right but it didn't like
that either...
[1,2] >>= (\x -> (\n -> [3,4])) x >>= \m -> return (n,m))
Any thoughts?
Matt
On 07/20/2013 12:23 AM, Matt Ford wrote:
Hi All,
I thought I'd have a go at destructing
[1,2] >>= \n -> [3,4] >>= \m -> return (n,m)
which results in [(1,3)(1,4),(2,3),(2,4)]
I started by putting brackets in
([1,2] >>= \n -> [3,4]) >>= \m -> return (n,m)
...
This is not the same expression
On Fri, Jul 19, 2013 at 3:23 PM, Matt Ford wrote:
> I started by putting brackets in
>
> ([1,2] >>= \n -> [3,4]) >>= \m -> return (n,m)
>
> This immediately fails when evaluated: I expect it's something to do
> with the n value now not being seen by the final return.
>
You're bracketing from the
Hi All,
I thought I'd have a go at destructing
[1,2] >>= \n -> [3,4] >>= \m -> return (n,m)
which results in [(1,3)(1,4),(2,3),(2,4)]
I started by putting brackets in
([1,2] >>= \n -> [3,4]) >>= \m -> return (n,m)
This immediately fails when evaluated: I expect it's something to do
with the n
10 matches
Mail list logo