bind :: Monad m => (a -> m b) -> m a -> m b

Felipe Lessa felipe.lessa at gmail.com
Thu Dec 11 12:33:10 UTC 2014


On 11-12-2014 08:59, Oliver Charles wrote:
> 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. ;) 

Since you didn't mention, I'm going to point out that you already can use:

>  (=<<) (traverse (\s ->
>                     case s of
>                       Sector{..} ->
>                         liftIO (do sectorDrawWalls
>                                    sectorDrawFloor
>                                    sectorDrawCeiling)))
>        (view sectors)

The infix vs prefix discussion looks like a red herring.  This proposal
is only about using the letters `bind` instead of the symbols `(=<<)`.
Which, besides "not being letters", I can only think of "it has 5 chars
instead of 4, messing with my indentation" as disadvantages.

Cheers,

-- 
Felipe.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141211/c636f707/attachment.sig>


More information about the Libraries mailing list