Skip to content

Instantly share code, notes, and snippets.

@Sintrastes
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sintrastes/692e0dedf42373fec10a to your computer and use it in GitHub Desktop.
Save Sintrastes/692e0dedf42373fec10a to your computer and use it in GitHub Desktop.
first (x,_,_) = x
second (_,y,_) = y
third (_,_,z) = z
filterFirst p x = p (first x)
filterSecond p x = p (second x)
filterThird p x = p (third x)
exists :: Int -> (a -> Bool) -> [(a,a,a)] -> [(a,a,a)]
exists 0 p xs = filter (filterFirst p) xs
exists 1 p xs = filter (filterSecond p) xs
exists 2 p xs = filter (filterThird p) xs
forall :: Eq a => Int -> (a -> Bool) -> [(a,a,a)] -> [(a,a,a)]
forall 0 p xs = do let ys = filter (filterFirst p) xs
if ys == xs
then xs
else []
forall 1 p xs = do let ys = filter (filterSecond p) xs
if ys == xs
then xs
else []
forall 2 p xs = do let ys = filter (filterThird p) xs
if ys == xs
then xs
else []
list = [(1,3,5),(1,5,4),(25,4,16),(1,5,250)]
list2 = exists 0 (< 1) list
list3 = exists 0 (== 1) list
|: exists 1 (== 5) |: exists 2 (> 100)
-- Composition operator for quantifiers
infixl 0 |:
(|:) :: Eq a => [(a,a,a)] -> ([(a,a,a)] -> [(a,a,a)]) -> [(a,a,a)]
(|:) x f = f x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment