module SpaceAge (Planet(..), ageOn) where
data Planet = Mercury
| Venus
| Earth
| Mars
| Jupiter
| Saturn
| Uranus
| Neptune
ageOn :: Planet -> Float -> Float
ageOn planet seconds =
case planet of {
Mercury -> seconds * 0.2408467
Venus -> seconds * 0.61519726
Earth -> seconds * 1
Mars -> seconds * 1.8808158
Jupiter -> seconds * 11.862615
Saturn -> seconds * 29.447498
Uranus -> seconds * 84.016846
Neptune -> seconds * 164.79132
}
Hello, when I compile the above Haskell Code, it gives me
error: parse error on input ‘->’
|
115 | Venus -> seconds * 0.61519726
All my cases are vertically aligned, so what's the issue?
Thanks
CodePudding user response:
Writing curly braces indicates to GHC that you don't want to use whitespace layout for determining the block structure, so then you would have to use semicolons to separate each of the cases.
But the preferred way is to just leave out the curly braces:
ageOn' :: Planet -> Float -> Float
ageOn' planet seconds =
case planet of
Mercury -> seconds * 0.2408467
Venus -> seconds * 0.61519726
Earth -> seconds * 1
Mars -> seconds * 1.8808158
Jupiter -> seconds * 11.862615
Saturn -> seconds * 29.447498
Uranus -> seconds * 84.016846
Neptune -> seconds * 164.79132