so my function 'flatten' is to take a list of characters and digits to a string
flatten :: [(Char, Int)] -> String
flatten [] = []
flatten [(x,y):xs)] = x:(show y flatten xs)
but I keep getting parse error, can anyone help me understand? Thanks.
parse error (possibly incorrect indentation or mismatched brackets)
|
18 | flatten :: [(Char, Int)] -> String
| ^
CodePudding user response:
The compile error likely originates from something before the flatten
function, for example you forgot to close a bracket.
As for the flatten
function itself, for the second clause you should not use square brackets, otherwise you define a pattern of a list of lists of 2-tuples. You thus use (x, y):xs)
as pattern:
flatten :: [(Char, Int)] -> String
flatten [] = []
flatten ((x,y):xs) = x : show y flatten xs
CodePudding user response:
flatten [(x,y):xs)] = x:(show y flatten xs)
^