No title

Anonymous Coward 2018-02-13 16:12:06.004857 UTC

1module SpaceAge (Planet(..), ageOn) where
2
3import qualified Data.Maybe as Maybe
4import qualified Data.HashMap.Strict as Map
5import Data.Hashable
6
7data Planet = Mercury
8 | Venus
9 | Earth
10 | Mars
11 | Jupiter
12 | Saturn
13 | Uranus
14 | Neptune
15
16
17planetMap :: Map.HashMap Planet Float
18planetMap = Map.fromList [(Mercury, 0.2408467),
19 (Earth, 1.0),
20 (Venus, 0.61519726),
21 (Mars, 1.8808158),
22 (Jupiter, 11.862615),
23 (Saturn, 29.447498),
24 (Uranus, 84.016846),
25 (Neptune, 164.79132)]
26
27{-- Returns how many earth years --}
28yearsOnEarth :: Float -> Float
29yearsOnEarth seconds = seconds / 31557600
30
31ageOn :: Planet -> Float -> Float
32ageOn planet seconds = yearsOnEarth seconds / (Maybe.fromMaybe 1.0 $ Map.lookup planet planetMap)