[Haskell-cafe] RE: Newbern's Example 7
Alson Kemp
Alson.Kemp at sloan.mit.edu
Sat Mar 12 20:34:03 EST 2005
Jeff,
Thank you for your reply.
>> After fn is lifted, where is "bind" used in allCombinations?
>The bind happens inside the liftM2 function, which can be defined as
>(taken from http://www.haskell.org/onlinereport/monad.html):
>liftM2 f = \a b -> do { a' <- a; b' <- b; return (f a' b') }
Using the above, I think that allCombinations can be rewritten:
allCombinations fn (l:ls) =
foldl (\a b -> do { a' <- a; b' <- b; return (fn a' b') }) l ls
I'm not sure how "allCombinations (+) [[1,2][2,3]]" gets to the final
result, since the above would seem to yield:
allCombinations (+) [1,2]:[[2,3]] =
foldl (\a b -> do { a' <- a; b' <- b; return (fn a' b') }) [1,2] [[2,3]]
allCombinations (+) [1,2]:[[2,3]] =
return ((+) [1,2] [2,3])
You mentioned on your site that the operation of the List monad is key to
comprehending this function, but I still wasn't able to grok it. Any
pointers would be appreciated.
- Alson
More information about the Haskell-Cafe
mailing list