Skip to content

Instantly share code, notes, and snippets.

@Rembane
Created January 27, 2013 20:36
Show Gist options
  • Save Rembane/4650339 to your computer and use it in GitHub Desktop.
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.
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