Created
April 9, 2017 19:08
-
-
Save essic/4d984d724fb0d9a60daac6228ad0c838 to your computer and use it in GitHub Desktop.
Simple abstract data type exemple 1 created by essic - https://repl.it/GEaw/39
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
accumulate :: (a -> b) -> [a] -> [b] | |
accumulate _ [] = [] | |
accumulate f (x:xs) = f x : accumulate f xs | |
data Planet = Mercury | |
| Venus | |
| Earth | |
| Mars | |
| Jupiter | |
| Saturn | |
| Uranus | |
| Neptune | |
ageOn :: Planet -> Float -> Float | |
-- ageOn = (*) . secondsPerYear | |
ageOn x y = secondsPerYear x * y | |
secondsPerYear :: Planet -> Float | |
secondsPerYear planet = earthYear * case planet of | |
Mercury -> 0.2408467 | |
Venus -> 0.61519726 | |
Earth -> 1 | |
Mars -> 1.8808158 | |
Jupiter -> 11.862615 | |
Saturn -> 29.447498 | |
Uranus -> 84.016846 | |
Neptune -> 164.79132 | |
where earthYear = 365.25 * 24 * 60 * 60 | |
main = do | |
print result | |
where result = accumulate (ageOn Mars) [1,2,3,4,5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment