bind :: Monad m => (a -> m b) -> m a -> m b
Oliver Charles
ollie at ocharles.org.uk
Thu Dec 11 10:59:44 UTC 2014
Many people seem to be suggesting that this isn't a useful function to
have, but I just found myself wanting it for a pattern that I write a
lot. The code in question is:
traverse
(\s ->
case s of
Sector{..} ->
liftIO (do sectorDrawWalls
sectorDrawFloor
sectorDrawCeiling))
=<< view sectors
That is, I want to traverse some sort of structure, and the structure
that I want to traverse itself comes from performing a monadic
action. Imo, this would be more readable as
bind (traverse (\s ->
case s of
Sector{..} ->
liftIO (do sectorDrawWalls
sectorDrawFloor
sectorDrawCeiling)))
(view sectors)
Whatever we call it, I do feel it has use -- `traverse f =<< m` comes up
a lot, but with a complex f, using =<< or >>= leads to less
readability. Maybe I spend too much time with Chris. ;)
-- ocharles
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141211/a4d52cbf/attachment-0001.sig>
More information about the Libraries
mailing list