Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind operator (=<<) with two parameters [duplicate]

Tags:

haskell

Could not come up with a better subject title, unfortunately ... sorry.

I have a function that takes two pure parameters and returns a monadic value. And I have two monadic values to be fed into it. This is probably something stupid that I am missing. I would normally use (=<<) if it was just one parameter but now I am stuck with two.

So I need a function with this type of signature

(a1 -> a2  -> m b) -> m a1 -> m a2 -> m b

Hoogle does not give me anything. I know I can just use 'do' notation but I was wondering if this can be done without? Is it possible to curry with the bind operator something like this:

(function =<< value1) =<< value2

I thought 'liftM2' could be of use but it takes a function that returns a pure value.

Thank you.

like image 258
r.sendecky Avatar asked Feb 13 '23 13:02

r.sendecky


1 Answers

One possible solution is to use join :: Monad m => m (m a) -> m a in conjunction with liftM2:

join $ liftM2 function value1 value2
like image 174
David Young Avatar answered Feb 22 '23 22:02

David Young