Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module HW1.T1
- ( Day (..)
- , afterDays
- , daysToParty
- , isWeekend
- , nextDay
- ) where
- import Numeric.Natural (Natural)
- data Day
- = Monday
- | Tuesday
- | Wednesday
- | Thursday
- | Friday
- | Saturday
- | Sunday
- deriving Show
- nextDay :: Day -> Day
- nextDay Monday = Tuesday
- nextDay Tuesday = Wednesday
- nextDay Wednesday = Thursday
- nextDay Thursday = Friday
- nextDay Friday = Saturday
- nextDay Saturday = Sunday
- nextDay Sunday = Monday
- afterDays :: Natural -> Day -> Day
- afterDays 0 day = day
- afterDays n day = afterDays (n - 1) (nextDay day)
- isWeekend :: Day -> Bool
- isWeekend Saturday = True
- isWeekend Sunday = True
- isWeekend _ = False
- counterForDays :: Day -> Natural -> Natural
- counterForDays Friday n = n
- counterForDays day n = counterForDays (nextDay day) (n + 1)
- daysToParty :: Day -> Natural
- daysToParty Friday = 0
- daysToParty day = counterForDays day 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement