Last active
August 29, 2015 14:06
-
-
Save cheecheeo/a37dd840f0356c30a795 to your computer and use it in GitHub Desktop.
Revisions
-
cheecheeo revised this gist
Sep 24, 2014 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,10 +17,10 @@ mkFoundItTriplet a x y z = -- | @FoundIt a@ is a semigroup -- -- prop> \a b c -> let (x, y, z) = mkFoundItTriplet a a b c in x <> (y <> z) == (x <> y) <> (z :: FoundIt Integer) -- prop> \a b c -> let (x, y, z) = mkFoundItTriplet b a b c in x <> (y <> z) == (x <> y) <> (z :: FoundIt Integer) -- prop> \a b c -> let (x, y, z) = mkFoundItTriplet c a b c in x <> (y <> z) == (x <> y) <> (z :: FoundIt Integer) -- prop> \a b c d -> let (x, y, z) = mkFoundItTriplet d a b c in x <> (y <> z) == (x <> y) <> (z :: FoundIt Integer) instance Semigroup (FoundIt a) where f1 <> f2 = if getFoundIt f1 then f1 else f2 -
cheecheeo revised this gist
Sep 24, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ mkFoundItTriplet :: (Eq a) => a -> a -> a -> a -> (FoundIt a, FoundIt a, FoundIt mkFoundItTriplet a x y z = (FoundIt (== a) x, FoundIt (== a) y, FoundIt (== a) z) -- | @FoundIt a@ is a semigroup -- -- prop> \a b c -> let (x, y, z) = mkFoundItTriplet a a b c in x <> (y <> z) == (x <> y) <> z -- prop> \a b c -> let (x, y, z) = mkFoundItTriplet b a b c in x <> (y <> z) == (x <> y) <> z -
cheecheeo created this gist
Sep 24, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ module FoundIt (FoundIt.elem) where import Data.Semigroup import Data.List.NonEmpty (NonEmpty(..)) data FoundIt a = FoundIt (a -> Bool) a instance (Eq a) => Eq (FoundIt a) where f1 == f2 = case (f1, f2) of (FoundIt _ x1, FoundIt _ x2) -> x1 == x2 && getFoundIt f1 == getFoundIt f2 mkFoundItTriplet :: (Eq a) => a -> a -> a -> a -> (FoundIt a, FoundIt a, FoundIt a) mkFoundItTriplet a x y z = (FoundIt (== a) x, FoundIt (== a) y, FoundIt (== a) z) -- | FoundIt is a semigroup -- -- prop> \a b c -> let (x, y, z) = mkFoundItTriplet a a b c in x <> (y <> z) == (x <> y) <> z -- prop> \a b c -> let (x, y, z) = mkFoundItTriplet b a b c in x <> (y <> z) == (x <> y) <> z -- prop> \a b c -> let (x, y, z) = mkFoundItTriplet c a b c in x <> (y <> z) == (x <> y) <> z -- prop> \a b c d -> let (x, y, z) = mkFoundItTriplet d a b c in x <> (y <> z) == (x <> y) <> z instance Semigroup (FoundIt a) where f1 <> f2 = if getFoundIt f1 then f1 else f2 getFoundIt :: FoundIt a -> Bool getFoundIt f = case f of FoundIt p x -> p x -- | Is @findMe@ an element of @xs'@? -- >>> FoundIt.elem 5 $ [1..10] -- True -- >>> FoundIt.elem 5 $ [1..4] -- False -- >>> FoundIt.elem 42 $ [1..4] -- False -- >>> FoundIt.elem 42 $ [42] -- True elem :: (Eq a) => a -> [a] -> Bool elem findMe xs' = case xs' of [] -> False (x:xs) -> getFoundIt . sconcat . fmap (FoundIt (== findMe)) $ x :| xs