Title: Compose monadic and pure function
Tags: haskell
Question: Let's find files that not exist in the current directory:
filterM (\f -&gt; return . not =<< doesFileExist f) files
And now I want to do it better with point notation:
filterM (liftM not . doesFileExist) files
Are there another approaches to do this? For example, later works not so good for composition of pure functions, need braces:
filterM (liftM (isExtensionPNG . not) . doesFileExist) files
Comment: I don't think the last example does what you intended. For that to typecheck, `isExtensionPNG` would have to have the type `Bool -> Bool`, which doesn't make much sense.

Comment: What you call “point notation” is usually called *“point-free style”* (or, more disparagingly, “pointless style”).

Comment: Agree with @hammar, you probably wanna use `not . isExtensionPNG`

Here is the accepted answer: You could define an infix operator to make it nicer to write:
infixr 9 .: -- same as .
(.:) 75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0 Monad m =&gt; (b -&gt; c) -&gt; (a -&gt; m b) -&gt; a -&gt; m c
f .: g = liftM f . g
filterM (isExtensionPNG .: not .: doesFileExist) files

Here is another answer: Since every monad is a functor with liftM as fmap, you can use the fact that fmap distributes over function composition.
fmap (f . g) = fmap f . fmap g
You can therefore write
filterM (liftM isExtensionPNG . liftM not . doesFileExist) files
Though to be honest, I prefer your original version.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:04/19/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<haskell>', 'Title': 'Compose monadic and pure function', 'ViewCount': 255, 'id': 10223198, 'user_AboutMe': '<p>I work for Google, love functional programming and Clojure, but code in C++, Java and JS.</p>\n', 'user_AccountId': 73618.0, 'user_DisplayName': 'demi', 'user_Reputation': 5234.0, 'user_Views': 394.0, 'user_id': 211885.0}}