How can I elegantly not do this. anyone in Haskell?
I am trying to figure out how to nullify the results of two boolean functions for example not . any
. I understand why it didn't work by breaking it down like below, but I'm not sure how to write a function that does this elegantly. I managed to docurry $ not . uncurry any
Prelude> :t not
not :: Bool -> Bool
Prelude> :t any
any :: Foldable t => (a -> Bool) -> t a -> Bool
Prelude> :t (.)
(.) :: (b -> c) -> (a -> b) -> a -> c
curry $ not . uncurry any
:: Foldable t => (a -> Bool) -> t a -> Bool
source to share
There is a standard point-free-ifier available separately or via lambdabot which gives:
18:02 <dmwit> ?pl \f xs -> any (\x -> not (f x)) xs
18:02 <lambdabot> any . (not .)
18:04 <dmwit> ?pl \f xs -> not (any f xs)
18:04 <lambdabot> (not .) . any
There are many ways to write this general operation .
Edit: Thanks to zudov for the following suggested additional text: you can also access the tool pointfree
by installing pointfree
or using one of the web interfaces (e.g. http://pointfree.io ).
source to share