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)’
You can use one of these:
liftM2 (+) a b
liftA2 (+) a b
(+) <$> a <*> b