Skip to content

Instantly share code, notes, and snippets.

@bkyrlach
Created October 23, 2020 04:40
Show Gist options
  • Save bkyrlach/ac40de48686c733a8cfedb637e85edf2 to your computer and use it in GitHub Desktop.
Save bkyrlach/ac40de48686c733a8cfedb637e85edf2 to your computer and use it in GitHub Desktop.
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Age where
main :: IO ()
main = do
print "Hello, world."
print $ show $ ageOn Mecury (earthYearInSeconds * 38)
data Planet =
Mecury
| Venus
| Earth
| Mars
| Jupiter
| Saturn
| Uranus
| Neptune
newtype Seconds = MkSeconds Float deriving (Show, Num, Fractional)
earthYearInSeconds :: Seconds
earthYearInSeconds = MkSeconds 31557600
planetFactor :: Planet -> Seconds
planetFactor p = MkSeconds $
case p of
Mecury -> 0.2408467
Venus -> 0.61519726
Earth -> 1
Mars -> 1.8808158
Jupiter -> 11.862615
Saturn -> 29.447498
Uranus -> 84.016846
Neptune -> 164.79132
ageOn :: Planet -> Seconds -> Seconds
ageOn p s = (s / earthYearInSeconds / (planetFactor p))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment