[Haskell-cafe] List Monads and non-determinism
Matt Ford
matt at dancingfrog.co.uk
Sat Jul 20 00:23:03 CEST 2013
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 value now not being seen by the final return.
It seems to me that the return function is doing something more than
it's definition (return x = [x]).
If ignore the error introduced by the brackets I have and continue to
simplify I get.
[3,4,3,4] >>= \m -> return (n,m)
Now this obviously won't work as there is no 'n' value. So what's
happening here? Return seems to be doing way more work than lifting the
result to a list, how does Haskell know to do this? Why's it not in the
function definition? Are lists somehow a special case?
Any pointers appreciated.
Cheers,
--
Matt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 234 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130719/73412eff/attachment.pgp>
More information about the Haskell-Cafe
mailing list