John Launchbury wrote:
test :: [Int]
test = do (x,z) - [(y,1),(2*y,2), (3*y,3)]
Just y - map isEven [z .. 2*z]
return (x+y)
isEven x = if even x then Just x else Nothing
I would expect this to be equivalent to
test = do (~(x,z), ~(Just y)) -
John Launchbury posed a nice puzzle about
mutual recursive bindings in the do notation:
test :: [Int]
test = do (x,z) - [(y,1),(2*y,2), (3*y,3)]
Just y - map isEven [z .. 2*z]
return (x+y)
isEven x = if even x then Just x else Nothing
Folks,
My student Levent Erkok and I have been playing about with the idea of mutual
recursive bindings in the do notation. Mostly it's clear how they should behave, but
we struggle with the following example. I would love to hear some (considered)
opinions about this.
John.