Created
October 23, 2020 04:40
-
-
Save bkyrlach/ac40de48686c733a8cfedb637e85edf2 to your computer and use it in GitHub Desktop.
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
{-# 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