Created
June 27, 2015 15:52
-
-
Save nkaretnikov/2cfec669c2297def5682 to your computer and use it in GitHub Desktop.
Animal and attribute
This file contains hidden or 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
-- For haskell202 | |
import Data.List (intercalate) | |
main :: IO () | |
main = loop [] [] | |
where | |
split = intercalate ", " . filter (not . null) | |
loop animal attribute = do | |
animal' <- getLine | |
attribute' <- getLine | |
acc (split [animal, animal']) (split [attribute, attribute']) | |
where | |
acc :: String -> String -> IO () | |
acc [] [] = putStrLn "no data provided" | |
acc an [] = do | |
putStrLn "no attribute provided" | |
loop an [] | |
acc [] at = do | |
putStrLn "no animal provided" | |
loop [] at | |
acc an at = do | |
putStrLn "done" | |
putStrLn an | |
putStrLn at | |
{- | |
ghci> main | |
dog | |
red | |
done | |
dog | |
red | |
ghci> main | |
dog | |
no attribute provided | |
cat | |
red | |
done | |
dog, cat | |
red | |
ghci> main | |
green | |
no animal provided | |
dog | |
yellow | |
done | |
dog | |
green, yellow | |
ghci> main | |
no data provided | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment