Haskell: getting rid of parentheses in liftM2

How to remove parentheses marked with ^ without entering new names? (better if it can be divided into several lines)

 liftM2 (+) (somefunc arg1 (get arg2)) (somefunc arg3 (get arg3)) ^ ^ ^ ^ - 
+4
source share
1 answer

You can get rid of the latter using $ , but the other obviously cannot be deleted without entering new names. A better solution would be to use the fact that any Monad m should also be Applicative and Functor (and there will be, GHC 7.10 will come)

Then your example will be

 import Control.Applicative ((<$>), (<*>)) (+) <$> somefunc arg1 (get arg2) <*> somefunc arg3 (get arg3) 
+16
source

Source: https://habr.com/ru/post/1264859/


All Articles