Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2019
101
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 -- of its sides.
  9. hypotenuse :: Double -> Double -> Double
  10. hypotenuse a b = sqrt (square a + square b)
  11.  
  12. -- | Square a number.
  13. square :: Num n => n -> n
  14. square x = x ^ 2
  15.  
  16. -- | Law of cosine
  17. law_of_cosines :: Double -> Double -> Double -> Double
  18. law_of_cosines a b gamma = sqrt $ a^2 + b^2 - 2 * a * b * cos (gamma/180 * pi)
  19.  
  20. -- | End of Code
  21.  
  22. SAMPLE RUNS IN GHCI:
  23. *Hypotenuse> law_of_cosines 4 5 6 1.1041395678396217
  24. Hypotenuse> law_of_cosines 1 1 60 0.9999999999999999
  25. *Hypotenuse> law_of_cosines 4 4 90 5.65685424949238
  26. *Hypotenuse> law_of_cosines 3 4 90 5.0
  27. *Hypotenuse> law_of_cosines 3 6 25 3.5175161217371276
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement