No title

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module SpaceAge (Planet(..), ageOn) where

import qualified Data.Maybe as Maybe
import qualified Data.HashMap.Strict as Map
import Data.Hashable

data Planet = Mercury
            | Venus
            | Earth
            | Mars
            | Jupiter
            | Saturn
            | Uranus
            | Neptune       


planetMap :: Map.HashMap Planet Float
planetMap = Map.fromList [(Mercury, 0.2408467),
                          (Earth, 1.0),
                          (Venus, 0.61519726),
                          (Mars, 1.8808158),
                          (Jupiter, 11.862615),
                          (Saturn, 29.447498),
                          (Uranus, 84.016846),
                          (Neptune, 164.79132)]

{-- Returns how many earth years --}
yearsOnEarth :: Float -> Float
yearsOnEarth seconds = seconds / 31557600

ageOn :: Planet -> Float -> Float
ageOn planet seconds = yearsOnEarth seconds / (Maybe.fromMaybe 1.0 $ Map.lookup planet planetMap)
32:24: Warning: Move brackets to avoid $
Found:
yearsOnEarth seconds /
(Maybe.fromMaybe 1.0 $ Map.lookup planet planetMap)
Why not:
yearsOnEarth seconds /
Maybe.fromMaybe 1.0 (Map.lookup planet planetMap)