implement eq and ord for shape
parent
2c704f6faa
commit
d6879da602
|
@ -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)
|
Loading…
Reference in New Issue