I have some code like this:
data Set = Set String [Int]
deriving (Show, Read)
getArr :: Set -> [Int]
getArr (Set _ arr) = arr
My goal is to write a function that will input a list of values into a tuple.
EG:
data --
"One" [1], "Two" [2], "Three" [3]
output: "One" [0, 1], "Two" [1,2], "Three" [3,3] with the input being [0, 1, 3]
My general aproach to this was to go recursively over the data going one by one and at the same time going over the list of values one by one using : to add it onto the first index.
I attempted to do something like:
addToSet :: [Set] -> [Int] -> [Set]
addToSet [] [] = []
addToSet (x:xs) (y:ys) = (getArr x : y) ++ addToSet xs
but i get an error saying :
Couldn't match type ‘[Int]’ with ‘Set’
Expected type: [Set]
Actual type: [[Int]]```
get Arr x : ywould result in aInt-list (result ofgetArr) being prepended to a [Int]` (they) - then the result of that (what ever it is supposed to be) is concatenated with a[Int] -> [Set](you only partial appliedxstoaddToSet) ... also: can you please make a better example (input toaddToSetand expected output)? Your example on the first half does not seem to associated to the second half at all