Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Zhang Xiaomenghan
  2. -- Exercise 1.4
  3.  
  4. -- | A module for working with triangles.
  5.  
  6. module Hypotenuse where
  7.  
  8. -- | Compute the length of the hypotenuse of a triangle from the lengths
  9. --   of its sides.
  10. hypotenuse :: Double -> Double -> Double
  11. hypotenuse a b = sqrt (square a + square b)
  12.  
  13. -- | Square a number.
  14. square :: Num n => n -> n
  15. square x = x ^ 2
  16.  
  17. -- | Law of cosine
  18. law_of_cosines :: Double -> Double -> Double -> Double
  19. law_of_cosines a b gamma = sqrt $ a^2 + b^2 - 2 * a * b * cos (gamma/180 * pi)
  20.  
  21.  
  22.  
  23. SAMPLE RUNS IN GHCI:
  24.  
  25. *Hypotenuse> law_of_cosines 4 5 6
  26. 1.1041395678396217
  27. Hypotenuse> law_of_cosines 1 1 60
  28. 0.9999999999999999
  29. *Hypotenuse> law_of_cosines 4 4 90
  30. 5.65685424949238
  31. *Hypotenuse> law_of_cosines 3 4 90
  32. 5.0
  33. *Hypotenuse> law_of_cosines 3 6 25
  34. 3.5175161217371276
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement