height end def area @width * height end end class Square def initialize(x) @x = x end def area @x * @x end end class Circle def initialize(r) @r = r end def area 3.14159 * @r end end
Square Float area (Circle r) = r * 3.14 area (Rectangle w h) = w * h area (Square x) = x * x circle = Circle 5 rectangle = Rectangle 2 3 square = Square 1.5
Square Float area (Circle r) = r * 3.14 area (Rectangle w h) = w * h area (Square x) = x * x circle = Circle 5 rectangle = Rectangle 2 3 square = Square 1.5 -- > area circle -- 15.700001
Square Float area (Circle r) = r * 3.14 area (Rectangle w h) = w * h area (Square x) = x * x circle = Circle 5 rectangle = Rectangle 2 3 square = Square 1.5 -- > area circle -- 15.700001 -- > :type area -- area :: Shape -> Float