Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The missing << operator [duplicate]

Tags:

haskell

monads

The Monad class defines a >> method, which sequences two monadic actions:

>> :: Monad m => m a -> m b -> m b

The binding operator >>= has a flipped-argument equivalent, =<<; as do the monadic function composition ('fish') operators >=> and <=<. There doesn't seem to be a <<, though (after a few minutes of Hoogling). Why is this?

Edit: I know it's not a big deal. I just like the way certain lines of code look with the left-pointing operators. x <- doSomething =<< doSomethingElse just looks nicer, with the arrows all going the same way, than x <- doSomethingElse >>= doSomething.

like image 311
Benjamin Hodgson Avatar asked Jul 17 '26 09:07

Benjamin Hodgson


1 Answers

To the best of my knowledge there is no good reason. Note, that your Monad should also be an instance of Applicative, so you can use <* and *> instead as your sequencing tools.

like image 63
Philip JF Avatar answered Jul 19 '26 01:07

Philip JF



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!