You are viewing a single comment's thread. Return to all comments →
how do you know how many lines to read? In a situation where a user is inputting a variable set of inputs, would this work?
If you run this it will just ask for inputs forever.
also, I think that you don't need to define your own read if your run function has a definition run :: [Int] -> [String]
run :: [Int] -> [String]
HackerRank tells you all you need to know about the input, so it's a completely different situation from an arbitrary CLI. This approach works for the type of problems on this particular site, and for the typical use case where input comes from a terminating program or a file.
It actually won't run forever because of a handy thing called EOF.
Nice idea about the type sig, though.
how would you write
ms <- forM [1..n] $ const $ getLine
let d = M.fromList $ (\[x,y] -> (x,y)) . words <$> ms
on one line?
d <- M.fromList <$> map ((\[x,y] -> (x,y)) . words) <$> replicateM n getLine