Reputation: 2085
So far I have these two functions:
splitLines :: String -> [[String]]
splitLines splitLinesStr = splitWords (lines splitLinesStr)
splitWords :: [String] -> [[String]]
splitWords splitWordStr = map words splitWordStr
Both work to aid in completing step 1-3. However I do not know how to how to create a tuple of an int and a list within a list (as stated by step 4). How would one go about doing this?
stage 1: the original input, for example,
"a&b b c.\na dd\n"
stage 2: the original input, split into a list of lines, as in
["a&b b c.", "a dd"]
stage 3: the list of lines, split further into a list of list of words, as in
[["a", "b", "b", "c"], ["a", "dd"]]
stage 4: the list of lists, "tupled" so that line numbers are attached to them, as in
[(1,["a", "b", "b", "c"]), (2,["a", "dd"])]
stage 5: the list of words (all at the top level) where each is paired with its line number, as in
[(1,"a"), (1,"b"), (1,"b"), (1,"c"), (2,"a"), (2,"dd")]
Upvotes: 0
Views: 97
Reputation: 34398
Hint 1: You can generate an infinite list of integer numbers with the following syntax:
[1..]
Hint 2: There is a function called zip
with a very suggestive type:
zip :: [a] -> [b] -> [(a, b)]
Upvotes: 1