[Haskell-cafe] Lists of Lists
jens.fisseler at FernUni-Hagen.de
Wed Mar 8 09:30:27 EST 2006
> > changeValue x i [xs] = [xs] !! i = x
> where x is the value to change to, i is the index of the value to change,
> and [xs] is the list.
> This however, dosen't work in Haskell. How would this be done in Haskell?
Think about what parts of the list you can reuse, how you can define
those parts and put them together.
You probably want to split the list at the index. 'splitAt' is the
function to use for this, as it will give you the resulting prefix and
suffix. The head of the suffix is the element you want to replace. So
you create a new list by appending the unaltered prefix, the new element
and the 'tail' of the suffix.
More information about the Haskell-Cafe