Sunday, September 7, 2008

Calculate your age in Haskell

You have to pass the current date as the first triple and your birthday as the second one.


age :: (Int,Int,Int) -> (Int,Int,Int) -> Int
age (d, m, y) (d2, m2, y2)
| m > m2 = y - y2
| m == m2 && d >= d2 = y - y2
| otherwise = y - y2 - 1