Created
January 27, 2013 20:36
-
-
Save Rembane/4650339 to your computer and use it in GitHub Desktop.
The awesome code of https://gist.github.com/4638535 implemented in Haskell, but sadly without GUI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.Maybe | |
isShootYear yr = [mod yr 400 == 0, mod yr 4 == 0, mod yr 100 /= 0] == [True, True, False] | |
isShootYearMsg True = "är ett skottår" | |
isShootYearMsg False = "är inte ett skottår" | |
maybeRead :: Read a => String -> Maybe a | |
maybeRead s = case reads s of | |
[(x, "")] -> Just x | |
_ -> Nothing | |
main = do | |
putStrLn "Ett år tak!" | |
yrstr <- getLine | |
let yr = maybeRead yrstr | |
if isJust yr | |
then sequence_ [putStrLn $ (isShootYearMsg $ isShootYear $ fromJust yr), putStrLn "", main] | |
else putStrLn "det där var fan inte ett år\n" >> main | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment