Created
August 26, 2012 17:14
-
-
Save axelGschaider/3481734 to your computer and use it in GitHub Desktop.
hCombiner
This file contains 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 characters
import Data.Monoid | |
--This is sparta! Filter the 500! | |
sparta :: (Integer -> Bool) -> [Integer] | |
sparta = flip filter [1 .. 500] | |
-- now the question is: how can multiple clauses for the same Integer be combined? | |
(<&&>) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool) | |
f <&&> g = \x -> f x && g x | |
(<||>) :: (a -> Bool) -> (a -> Bool) -> a -> Bool | |
f <||> g = \x -> f x || g x | |
--try | |
nobodyLives = sparta $ odd <&&> even | |
everybodyLives = sparta $ odd <||> even | |
someLive = sparta $ odd <&&> (<100) <||> (>400) | |
-- nice. A bit more generic? | |
(<++>) :: (Monoid m) => (a -> m) -> (a -> m) -> a -> m | |
f <++> g = \x -> (f x) `mappend` (g x) | |
-- but there has got to be something more that I'm missing right? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment