Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding multiple arguments

Tags:

haskell

monads

In Haskell, there is:

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

Is there a function:(?)

bind2 :: Monad m => m a -> m b -> (a -> b -> m c) -> m c
like image 511
ThePiercingPrince Avatar asked Nov 29 '22 15:11

ThePiercingPrince


2 Answers

This is what do notation is meant for.

bind2 :: (Monad m) => m a -> m b -> (a -> b -> m c) -> m c
bind2 ma mb f = do
  a <- ma
  b <- mb
  f a b

It's so simple that I probably wouldn't even define an extra operator for it, rather I'd just use do notation directly.

like image 21
Chris Taylor Avatar answered Dec 01 '22 05:12

Chris Taylor


Not quite, but you could use

bind2 :: Monad m => m a -> m b -> (a -> b -> m c) -> m c
bind2 x y f = join $ liftM2 f x y
like image 140
cdk Avatar answered Dec 01 '22 06:12

cdk