Skip to content

Instantly share code, notes, and snippets.

@lepinay
Last active August 29, 2015 14:14
Show Gist options
  • Save lepinay/68c41743110de3ceec1e to your computer and use it in GitHub Desktop.
Save lepinay/68c41743110de3ceec1e to your computer and use it in GitHub Desktop.
module LeapYear where
data Check a = Check (a -> Bool)
isLeap (Check check) n = check n
instance Monad (Check) where
return a = Check (\_ -> True)
(Check check) >>= cont = Check (\n -> isLeap (cont n) n ) -- check n && cont n
divby b = Check( \ n -> mod n b == 0)
except (Check check) = Check( \ n ->not $ check n )
unless (Check check) = Check( \ n ->check n )
isLeapYear n =
isLeap
$ do
divby 4
except $ divby 100
unless $ divby 400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment