75.4k views
4 votes
The function leap n, which takes an integer n as input, and returns True if the year n is a leap year, and False otherwise. NOTE: Please provide function declaration [2 marks]. Leap years are those that are evenly divisible by 4, except any year that is also evenly divisible by 100 unless that year is also evenly divisible by 400. So, for example, 1996, 2012, and 2020 are all leap years, but 2100, 2200, and 2300 are not leap years, because although they are all evenly divisible by 4, they are also evenly divisible by 100. However, 1600, 2000, and 2400 are leap years, because although they are divisible by 100, they are also divisible by 400. The Haskell interaction may look like: > leap 1996 True > leap 2000 True > leap 2100 False

User Jaya Mayu
by
6.0k points

1 Answer

5 votes

Answer:

Step-by-step explanation:

The following code snippet is a leap year checker written in Haskell which checks to see if the year is a leap year and then outputs a boolean value.

isDivisibleBy :: Integral n => n -> n -> Bool

isDivisibleBy x n = x `rem` n == 0

leap_n :: Integer -> Bool

leap_n year

| divBy 400 = True

| divBy 100 = False

| divBy 4 = True

| otherwise = False

where

divBy n = year `isDivisibleBy` n

User Steed
by
5.0k points