Advertisement
Guest User

Untitled

a guest
Oct 7th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Gabe Schoenbach
  2. -- Exercise 1.1
  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.  
  10. hypotenuse :: Double -> Double -> Double
  11. hypotenuse a b = sqrt (square a + square b)
  12.  
  13. -- | Square a number.
  14.  
  15. square :: Num n => n -> n
  16. square x = x ^ 2
  17.  
  18. -- Exercise 1.4
  19. -- | Change degrees into radians.
  20.  
  21. deg_to_rad :: Double -> Double
  22. deg_to_rad d =  d * pi / 180
  23.  
  24. -- | Compute the length of one side of a triangle from the lengths of the other two sides a and b and gamma, the angle (in degrees) between a and b.
  25.  
  26. law_of_cosines :: Double -> Double -> Double -> Double
  27. law_of_cosines a b gamma = sqrt (square a + square b - (2 * a * b * cos (deg_to_rad gamma)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement