Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you lift a binary function to monad transformers?

I know you can lift functions to monads with liftM, but I it doesn’t seem to work with binary functions.

I tried to lift (+) but it didn’t work

a = return 1 :: ExceptT String Maybe Int
b = return 2 :: ExceptT String Maybe Int
liftM (+) a b

• Couldn't match expected type ‘ExceptT String Maybe Int -> t’
                  with actual type ‘ExceptT String Maybe (Int -> Int)’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use one of these:

liftM2 (+) a b
liftA2 (+) a b
(+) <$> a <*> b
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading