2
votes

I am a newbie in Haskell. Let says my program want to calculate something from this pattern of input:

a1 b1 c1
a2 b2 c2
...
16 b6 c6

The input contains 6 lines and each line has 3 numbers I want to get data as [(Integer, Integer, Integer)] but limit the length of the list to be only 6 before going to the calculation.

How could I do this? Also, how could I get a length from [(Integer, Integer, Integer)]

Thank you for your help

1
I'd start with readFile, splitOn, and read, and then post what you have as a question. - Reactormonk

1 Answers

6
votes

There are three steps to this:

  1. Read 6 lines
  2. Break each line into the (hopefully three) parts
  3. Convert to the desired result

Some sample code is below:

input = do
  lines <- sequence $ take 6 $ repeat readLn
  let table = words <$> lines
  return [(a, b, c) | [a,b,c] <- table]

This gives input :: IO [(String, String, String)] but I'm sure you could modify this to give you what you want.