Skip to content

Instantly share code, notes, and snippets.

@nkaretnikov
Created June 27, 2015 15:52
Show Gist options
  • Save nkaretnikov/2cfec669c2297def5682 to your computer and use it in GitHub Desktop.
Save nkaretnikov/2cfec669c2297def5682 to your computer and use it in GitHub Desktop.
Animal and attribute
-- 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