Created
May 2, 2019 18:23
-
-
Save dewey92/be6a66a5ee81f10ed8fcd0eaa99a76d4 to your computer and use it in GitHub Desktop.
Arbitrary ADT
This file contains hidden or 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
| -- Data | |
| data Shape | |
| = Rectangle Number Number -- length, height | |
| | Triangle Number Number -- base, height | |
| | Circle Number -- radius | |
| | Square Number -- length | |
| -- Behaviour | |
| area :: Shape -> Number | |
| area (Rectangle l h) = l * h | |
| area (Triangle b h) = b * h / 2 | |
| area (Circle r) = 3.14 * r * r | |
| area (Square l) = l * l | |
| -- Example | |
| area (Rectangle 5 4) == 20 | |
| area (Circle 7) == 154 | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment