Advertisement
alyoshinkkaa

Untitled

Sep 23rd, 2024
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module HW1.T1
  2.   ( Day (..)
  3.   , afterDays
  4.   , daysToParty
  5.   , isWeekend
  6.   , nextDay
  7.   ) where
  8.  
  9. import Numeric.Natural (Natural)
  10.  
  11. data Day
  12.   = Monday
  13.   | Tuesday
  14.   | Wednesday
  15.   | Thursday
  16.   | Friday
  17.   | Saturday
  18.   | Sunday
  19.   deriving Show
  20.  
  21. nextDay :: Day -> Day
  22. nextDay Monday = Tuesday
  23. nextDay Tuesday = Wednesday
  24. nextDay Wednesday = Thursday
  25. nextDay Thursday = Friday
  26. nextDay Friday = Saturday
  27. nextDay Saturday = Sunday
  28. nextDay Sunday = Monday
  29.  
  30. afterDays :: Natural -> Day -> Day
  31. afterDays 0 day = day
  32. afterDays n day = afterDays (n - 1) (nextDay day)
  33.  
  34. isWeekend :: Day -> Bool
  35. isWeekend Saturday = True
  36. isWeekend Sunday = True
  37. isWeekend _ = False
  38.  
  39.  
  40. counterForDays :: Day -> Natural -> Natural
  41. counterForDays Friday n = n
  42. counterForDays day n = counterForDays (nextDay day) (n + 1)
  43.  
  44. daysToParty :: Day -> Natural
  45. daysToParty Friday = 0
  46. daysToParty day = counterForDays day 0
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement