1 2 3 4 5 6 7 8 9 10 11 12 13 | module LeapYear (isLeapYear, isLeapYear2) where isLeapYear :: Int -> Bool isLeapYear year | year `mod` 100 == 0 && year `mod` 400 /= 0 = False | year `mod` 4 == 0 = True | otherwise = False isLeapYear2 :: Int -> Bool isLeapYear2 year | year `mod` 4 /= 0 = False | year `mod` 100 == 0 && year `mod` 400 /= 0 = False | otherwise = True |

module LeapYear (isLeapYear, isLeapYear2) where
isLeapYear :: Int -> Bool
isLeapYear year
| year `mod` 100 == 0 && year `mod` 400 /= 0 = False
| year `mod` 4 == 0 = True
| otherwise = False
isLeapYear2 :: Int -> Bool
isLeapYear2 year
| year `mod` 4 /= 0 = False
| year `mod` 100 == 0 && year `mod` 400 /= 0 = False
| otherwise = True

@NobbZ thinks this looks great

## Comments

As noted on my other language submissions for leap, I'm torn about which ordering of predicates is most clear.

This is my first haskell code. Feel free to suggest style/layout/lint concerns. ( I'm still waiting on hlint to compile :) )

Since we are using the pattern

`( a `mod` b == 0)`

to check if b divides a repeatedly, it makes sense to abstract that pattern as a function.I also defined (-->) as logical implication, which allows me define isLeapYear as-

isLeapYear y = 4 `divides` y && 100 `divides` y --> 400 `divides` y

@shitikanth : Thanks for reviewing!

Excellent idea on extracting out the

`divides`

logic.I don't think I quite understand how/why you defined

`-->`

. Checking your code: http://exercism.io/submissions/599a075da0d647bdbc31183848cee018.You're not logged in right now. Please login via GitHub to comment