Skip to content

Instantly share code, notes, and snippets.

@jackwillis
Created July 28, 2017 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackwillis/9a8e8135bc8742c13ee263d3dc684cef to your computer and use it in GitHub Desktop.
Save jackwillis/9a8e8135bc8742c13ee263d3dc684cef to your computer and use it in GitHub Desktop.
NaiveTime in Haskell
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