Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.56 KB | None | 0 0
  1. //Ex 1.a
  2. type PclShape =
  3.     |Rectangle of float*float
  4.     |RightTriangle of float*float
  5.  
  6. //Ex 1.b
  7. let rect = Rectangle(5.0,6.0)
  8. let triang = RightTriangle(3.0,4.0)
  9.  
  10. //Ex 1.c
  11. let pclArea shape =
  12.     match shape with
  13.     |Rectangle (a,b)-> a * b
  14.     |RightTriangle (a,b)-> a * b / 2.0
  15.  
  16.  
  17.  
  18. //Ex 1.d
  19. let pclPerimeter shape =
  20.     match shape with
  21.     |Rectangle (a,b)-> 2.0*a + 2.0*b
  22.     |RightTriangle (a,b)-> a + b + ( (a*a + b*b)**0.5 )
  23.  
  24.  
  25. type sides = {sideA : float; sideB : float}
  26. type PclShapeR =
  27.     |Rectangle of sides
  28.     |RightTriangle of sides
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement