implement eq and ord for shape

main
Brian Hicks 2021-11-08 09:52:39 -06:00
parent 2c704f6faa
commit d6879da602
1 changed files with 17 additions and 0 deletions

17
src/Shape.idr Normal file
View File

@ -0,0 +1,17 @@
data Shape = Triangle Double Double
| Rectangle Double Double
| Circle Double
area : Shape -> Double
area (Triangle base height) = base * height / 2
area (Rectangle width height) = width * height
area (Circle radius) = pi * radius * radius
Eq Shape where
(==) (Triangle base height) (Triangle base' height') = base == base' && height == height'
(==) (Rectangle width height) (Rectangle width' height') = width == width' && height == height'
(==) (Circle radius) (Circle radius') = radius == radius'
(==) _ _ = False
Ord Shape where
compare x y = compare (area x) (area y)