--data Shape = Circle Float Float Float | Rect Float Float Float Float deriving (Show)
data Shape = Circle { x :: Float
, y :: Float
, r :: Float
} |
Rect { x1 :: Float
, y1 :: Float
, x2 :: Float
, y2 :: Float
} deriving(Show)
area :: Shape -> Float
area (Circle _ _ r) = pi*r**2
area (Rect x1 y1 x2 y2) = abs (x2-x1)*(y2-y1)
transform :: Shape -> Float -> Float -> Shape
transform (Circle x y r) x' y' = Circle (x+x') (y+y') (r)
transform (Rect x1 y1 x2 y2) x' y' = Rect (x1+x') (y1+y') (x2+x') (y2+y')
main = do
let shape1 = Circle 0 0 1
let shape2 = Rect 0 0 1 1
print(shape1)
print(x2 shape2)
print(area $ Rect 0 0 4 4)
print(area $ Circle 1 5 2)
print(area shape1)
print(transform shape1 1 1)
print(transform shape2 (-2.5) 2)