One of the nice things about Haskell is the ability to use infix notation.
1 : 2 : 3 : [] :: Num a => [a]
2 + 4 * 3 + 5 :: Num a => a
But this power is suddenly and sadly lost when the operator needs to be lifted.
liftM2 (*) (liftM2 (+) m2 m4) (liftM2 (+) m3 m5)
liftM2 (:) m1 (liftM2 (:) m2 (liftM2 (:) m3 mE))
It is possible to define similar operators in order to regain this power
(.*) = liftM2 (*)
(.+) = liftM2 (+)
(.:) = liftM2 (:)
m1, m2, m3, m4, m5 :: Monad m, Num a => m a
mE = return [] :: Monad m => m [a]
m1 .: m2 .: m3 .: mE :: Monad m, Num a => m [a]
m2 .+ m4 .* m3 .+ m5 :: Monad m, Num a => m a
But it is tedious to need to rename every operator I want to use in a monadic context. Is there a better way? Template Haskell, perhaps?
liftM2 (+) readInt readInt
- in this case I would want thereadInt
action performed twice, rather than only once, since it will possibly grab a different int the second time. – Dictaphone