Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I elegantly do not . any in Haskell?

Tags:

haskell

I'm trying to figure out how to negate the results of two parameter boolean function like not . any. I understand why it didn't work by breaking it down as shown below, but I'm not sure how to write a function that does this elegantly. I managed to do curry $ 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
like image 421
ssh Avatar asked Apr 24 '15 00:04

ssh


1 Answers

There is a standard point-free-ifier, available standalone 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 spell this general operation.

Edit: Thanks to zudov for the following suggested extra text: You can also access pointfree tool by installing pointfree or using one of web interfaces (e.g. http://pointfree.io).

like image 109
Daniel Wagner Avatar answered Sep 30 '22 09:09

Daniel Wagner