aelve / haskell-issues

An unofficial issue tracker for all things Haskell-related
18 stars 0 forks source link

do notation: Traversal sugar #45

Open Gurkenglas opened 7 years ago

Gurkenglas commented 7 years ago

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.

neongreen commented 7 years ago

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

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

Gurkenglas commented 7 years ago

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

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

Gurkenglas commented 7 years ago

Eureka!

Actually looks like Edward Kmett already wrote that 8 years ago.