haskell-issues icon indicating copy to clipboard operation
haskell-issues copied to clipboard

do notation: Traversal sugar

Open Gurkenglas opened this issue 8 years ago • 3 comments

In place of any last line of a do block reading foo $ \x -> do, you should be able to write something like x <-- foo and continue in the same do block. (Perhaps only as long as you stay in the same monad?)

The primary use case I'm thinking of is i <-- forM [1..10], but arbitrary traversals also suggest themselves. One might also want versions for different arities, for cases like sequence $ do or indexed traversals.

Gurkenglas avatar Dec 09 '16 04:12 Gurkenglas

(I actually like it that I have to indent the body of a for_ loop, though.)

What about \x <- foo instead, by the way?

neongreen avatar Dec 09 '16 11:12 neongreen

<-- should not preserve the lambda symbol: Neither does <-.

(Note x <- foo = x <-- (>>=) foo.)

Gurkenglas avatar Dec 09 '16 15:12 Gurkenglas