Created
July 28, 2017 01:52
-
-
Save jackwillis/9a8e8135bc8742c13ee263d3dc684cef to your computer and use it in GitHub Desktop.
NaiveTime in Haskell
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 | |
data NaiveTime = NT Int Int deriving (Show, Eq) | |
instance Monoid NaiveTime where | |
mempty = NT 0 0 | |
mappend (NT h m) (NT h' m') = NT h'' m'' | |
where h'' = (h + h' + ((m + m') `quot` 60)) `mod` 24 | |
m'' = (m + m') `mod` 60 | |
-- One hour and forty-five minutes after 19:48 is 21:33 | |
main = print $ (NT 19 48) <> (NT 1 45) == (NT 21 33) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment