Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- type Rectangle = {Length: int; Width: int}
- type Square = {Length:int}
- type Circle = {Radius: float}
- type Shape = Rectangle of float * float | Square of float | Circle of float
- let areaof shape =
- match shape with
- | Rectangle (x, y) -> x * y
- | Square x -> x * x
- | Circle radius -> 3.14 * radius * radius
- | _ -> failwith "Undefined shape"
- let rect = Rectangle(3.0,4.0)
- let circle = Circle(51.0)
- let square = Square(13.0)
- let rectArea = areaof rect
- let squareArea = areaof square
- let circleArea = areaof circle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement