Advertisement
Guest User

Untitled

a guest
Dec 14th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.55 KB | None | 0 0
  1. open System
  2.  
  3. type Rectangle = {Length: int; Width: int}
  4. type Square = {Length:int}
  5. type Circle = {Radius: float}
  6. type Shape = Rectangle of float * float | Square of float | Circle of float
  7. let areaof shape =
  8.     match shape with
  9.     | Rectangle (x, y)  -> x * y
  10.     | Square x -> x * x
  11.     | Circle radius -> 3.14 * radius * radius
  12.     | _ -> failwith "Undefined shape"
  13.  
  14. let rect = Rectangle(3.0,4.0)
  15. let circle = Circle(51.0)
  16. let square = Square(13.0)
  17. let rectArea = areaof rect
  18. let squareArea = areaof square
  19. let circleArea = areaof circle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement