I'm trying to write a function that will append a given value to the innermost lists of a nested list structure, but I'm running into errors with type when I'm not even sure what the type signature of such a function would be.
digpend a xs = case xs of [_:_] -> map (digpend a) xs
[[]] -> [[a]]
xs -> a:xs
For example,
digpend 555 [ [ [ 5,1,-12,33 ] , [ 6,22 ] ] , [ [ -9,0,9,12,83 ] ] ]
should return
[ [ [ 555,5,1,-12,33 ] , [ 555,6,22 ] ] , [ [ 555,-9,0,9,12,83 ] ] ]
and ideally, it would work on any level of nesting by recursion. Is this allowed?
(digpend a)
wants to be polymorphic isn’t necessarily a problem. – PLL Jun 28 '13 at 16:15