159.272 Programming Language Paradigms Assignment 1
Write a Haskell function that takes a date and an offset as parameters and returns the date that is a certain number of days before or after the input date. The number of days is given by the offset parameter.
Top-level function
The top-level function must have the following function declaration:
adjust_date :: (Int, Int, Int) -> Int -> (Int, Int, Int)
Thefirstparameterisatuplethatspecifiesaday,monthandyear,e.g.(24, 4, 1959). The date must be a valid date between (1, 1, 1600) and (31, 12, 3000). The second parameter specifies an offset between -25 and 25. If the offset is negative, then the resulting date is before the given date; if it is positive, the resulting date is after the given date. For example, if the date is (24, 4, 1959) and the offset is 9, then the resulting date is (3, 5, 1959). On the other hand, if the offset is -5, then the resulting dateis(19, 4, 1959).
The top-level function may call other Haskell functions to achieve the task.
Things to watch out for
The offset may shift the date into the next or the previous month. Obviously not every month has the same number of days, and February (the second month) has either 28 or 29 days, depending on whether the year is a leap year or not.
It may also be the case that the date is shifted into the next or the previous year. This also needs to be taken care of. However, due to the range of the offset being restricted, the shift will also be less than a month.
Tip: a leap year is a year that is an integer multiple of 4 (except for years evenly divisible by 100, but not by 400).
What we are looking for
- A set of Haskell functions that do not depend on any modules to be imported.
- Each function needs to have a comment explaining its purpose.
- The top-level function must adhere to the function declaration shown above.
- If an incorrect date or offset is given as parameter, i.e. a date or offset not within the permissible range, a sensible error message needs to be displayed.