Zorikto

lab1hask

Apr 11th, 2021 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Lab1 where
  2.  
  3. square :: Int->Int
  4. square x = x*x
  5.  
  6. prod :: Int->Int->Int
  7. prod x y = x*y
  8.  
  9. ispositive :: Int->Bool
  10. ispositive x = if x>0 then True else False
  11.  
  12. singnum :: Int->Int
  13. singnum x = if x>0 then 1 else if x<0 then -1 else 0
  14.  
  15. max3 :: Int->Int->Int->Int
  16. max3 a b c = if a>b && a>c then a else if b>a && b>c then b else c
  17.  
  18. sort2 :: Int->Int->(Int,Int)
  19. sort2 a b = if a > b then (b, a) else (a, b)
  20.  
  21. bothTrue :: Bool->Bool->Bool
  22. bothTrue a b = if a == True then if b == True then True else False else False
  23.  
  24. solved :: Double->Double->(Bool,Double)
  25. solved a b = if ( a == 0 && b /= 0) then (False, 0) else if (a == 0 && b == 0) then (True, 0) else (True, -b/a)
  26.  
  27. isParallel :: ((Double, Double), (Double, Double))->((Double, Double), (Double, Double))->Bool
  28. isParallel (x1, y1) (x2, y2) = if (fst y1 - fst x1) * (snd y2 - snd x2) - ( fst y2 - fst x2) * (fst y1 - snd x1) == 0 then True else False
  29.  
  30. isIncluded :: (Double, (Double, Double))->(Double, (Double, Double))->Bool
  31. isIncluded (r1, (x1, y1)) (r2, (x2, y2)) = if sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2) + r2 <= r1 then True else False
  32.  
  33. scalar :: (Double, Double)->(Double, Double)->Bool
  34. scalar (x1, y1) (x2, y2) = if x1 * x2 + y1 * y2 == 0 then True else False
  35. isRectangular :: (Double, Double)->(Double, Double)->(Double,Double)->Bool
  36. isRectangular (x1, y1) (x2, y2) (x3, y3) = if scalar ((x2 - x1), (y2 - y1)) ((x3 - x1), (y3 - y1)) == True || scalar ((x1 - x2), (y1 - y2)) ((x3 - x2), (y3 - y2)) == True || scalar ((x1 - x3), (y1 - y3)) ((x2 - x3), (y2 - y3)) == True then True else False
  37.  
  38. isTriangle :: Double->Double->Double->Bool
  39. isTriangle a b c = if a + b > c && b + c > a && a + c > b then True else False
  40.  
  41. isSorted :: Int->Int->Int->Bool
  42. isSorted a b c = if((a < b && b < c) || (a > b && b > c)) then True else False
Add Comment
Please, Sign In to add comment