Greg Peckory
Greg Peckory

Reputation: 8058

Input line of numbers in haskell and convert to list

Basically what is said in the title.

I would like to input

4 6 17 4

and it would give me the list

[4, 6, 17, 4]

Upvotes: 0

Views: 859

Answers (1)

ErikR
ErikR

Reputation: 52029

main = do
  ln <- getLine
  let ints = map read (words ln)  :: [Int]
  ... do something with ints...

ints is a list of Int values.

The type signature :: [Int] is needed so read knows what to return.

Upvotes: 3

Related Questions