Skip to content

Instantly share code, notes, and snippets.

@jgcoded
Last active October 5, 2015 03:28
Show Gist options
  • Save jgcoded/6c7c77938d253baa4ddf to your computer and use it in GitHub Desktop.
Save jgcoded/6c7c77938d253baa4ddf to your computer and use it in GitHub Desktop.
Use this snippet to parse any line-delimited user input into a list of a specified type
{-
If you want to read in Strings: getInputLinesWith id n
if you want to read in Ints: getInputLinesWith read n :: IO [Int]
where n is how many lines to take input from
-}
getInputLinesWith :: (String -> a) -> Int -> IO [a]
getInputLinesWith f n = fmap (map f) (replicateM n getLine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment