Skip to content

Instantly share code, notes, and snippets.

@josue
Created July 18, 2014 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josue/cf24df20f047ae3a6c37 to your computer and use it in GitHub Desktop.
Save josue/cf24df20f047ae3a6c37 to your computer and use it in GitHub Desktop.
Experimenting with Haskell - simple script that reads name, validates with functions and writes output to file.
import System.Environment
import Data.Char
main = promptNameAndSave
matchesName s = if (map toUpper s) == "JOSUE" then True else False
checkIfBeast str = if matchesName str then "a BEAST !" else "normal."
finalMessage h i = "Thanks " ++ h ++ ", you are " ++ i
addToFile s = writeFile "is_beast.out" (s ++ "\n")
promptNameAndSave = do
putStrLn "What is your name?"
name <- getLine
let message = finalMessage name (checkIfBeast name)
putStrLn $ "\n" ++ message
addToFile message
@josue
Copy link
Author

josue commented Aug 7, 2014

Run in command-line as:

runhaskell check_if_beast.hs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment