Home > Software engineering >  How do you lift a binary function to monad transformers?
How do you lift a binary function to monad transformers?

Time:01-09

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)’

CodePudding user response:

You can use one of these:

liftM2 ( ) a b
liftA2 ( ) a b
( ) <$> a <*> b
  • Related