Space Age in Haskell
Given an age in seconds, calculate how old someone is in terms of a given planet's solar years.
exercism fetch haskell space-age
Given an age in seconds, calculate how old someone would be on:
- Earth: orbital period 365.25 Earth days, or 31557600 seconds
- Mercury: orbital period 0.2408467 Earth years
- Venus: orbital period 0.61519726 Earth years
- Mars: orbital period 1.8808158 Earth years
- Jupiter: orbital period 11.862615 Earth years
- Saturn: orbital period 29.447498 Earth years
- Uranus: orbital period 84.016846 Earth years
- Neptune: orbital period 164.79132 Earth years
So if you were told someone were 1,000,000,000 seconds old, you should be able to say that they're 31.69 Earth-years old.
If you're wondering why Pluto didn't make the cut, go watch this youtube video.
In this exercise, we provided the definition of the
algebric data type
You need to implement the
ageOn function, that calculates how many
years old someone would be on a
Planet, given an age in seconds.
Your can use the provided signature if you are unsure about the types, but don't let it restrict your creativity:
ageOn :: Planet -> Float -> Float
For installation and learning resources, refer to the exercism help page.
Running the tests
To run the test suite, execute the following command:
If you get an error message like this...
No .cabal file found in directory
You are probably running an old stack version and need to upgrade it.
Otherwise, if you get an error message like this...
No compiler found, expected minor version match with... Try running "stack setup" to install the correct GHC...
Just do as it says and it will download and install the correct compiler version:
If you want to play with your solution in GHCi, just run the command:
Feedback, Issues, Pull Requests
The exercism/haskell repository on GitHub is the home for all of the Haskell exercises.
If you have feedback about an exercise, or want to help implementing a new one, head over there and create an issue. We'll do our best to help you!
Partially inspired by Chapter 1 in Chris Pine's online Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=01
Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.