Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: get rid of parentheses in liftM2

Tags:

haskell

How to remove the parentheses marked with ^, without introducing new names? (better if it can be splitted into multiple lines)

liftM2 (+) (somefunc arg1 (get arg2)) (somefunc arg3 (get arg3))
           ^                        ^ ^                        ^
                                     -
like image 807
Not an ID Avatar asked Dec 04 '22 04:12

Not an ID


1 Answers

You can get rid of the last one by using $, but the other one cannot obviously be removed without introducing new names. A better solution may be to use the fact that any Monad m should also be Applicative and Functor (and will be, come GHC 7.10)

Your example then becomes

import Control.Applicative ((<$>), (<*>))

(+) <$> somefunc arg1 (get arg2) <*> somefunc arg3 (get arg3)
like image 109
Sarah Avatar answered Jan 02 '23 00:01

Sarah