RosettaCodeData/Task/Polymorphism/Ela/polymorphism-1.ela

44 lines
844 B
Text
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
type Point = Point x y
instance Show Point where
2016-12-05 22:15:40 +01:00
show (Point x y) = "Point " ++ (show x) ++ " " ++ (show y)
2013-04-10 23:57:08 -07:00
instance Name Point where
getField nm (Point x y)
| nm == "x" = x
| nm == "y" = y
| else = fail "Undefined name."
2016-12-05 22:15:40 +01:00
isField nm _ = nm == "x" || nm == "y"
2013-04-10 23:57:08 -07:00
pointX = flip Point 0
pointY = Point 0
pointEmpty = Point 0 0
type Circle = Circle x y z
instance Show Circle where
2016-12-05 22:15:40 +01:00
show (Circle x y z) =
2013-04-10 23:57:08 -07:00
"Circle " ++ (show x) ++ " " ++ (show y) ++ " " ++ (show z)
instance Name Circle where
getField nm (Circle x y z)
| nm == "x" = x
| nm == "y" = y
| nm == "z" = z
| else = fail "Undefined name."
2016-12-05 22:15:40 +01:00
isField nm _ = nm == "x" || nm == "y" || nm == "z"
2013-04-10 23:57:08 -07:00
circleXZ = flip Circle 0
circleX x = Circle x 0 0
circleYZ = Circle 0
circleY y = Circle 0 y 0
circleZ = Circle 0 0
circleEmpty = Circle 0 0 0