[Haskell-cafe] Lists of Lists

Thomas Davie tom.davie at gmail.com
Wed Mar 8 09:28:45 EST 2006

On 8 Mar 2006, at 14:21, zell_ffhut wrote:

> Thank you, It's working as planed now
> Trying to do a function now that changes the value of an element of  
> the
> list. In programming languages i've used in the past, this would be  
> done
> somthing like -
>> 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?

Put simply it isn't.

One of the percepts of a functional language is that variables are  
bound, not set - once a variable has a value it has that value  
forever.  What you want to do is return a new list, that looks like  
the old one, but has one value changed

changeValue x 0 (y:ys) = (x:ys)
changeValue x n (y:ys) = y:(changeValue x (n-1) ys)


More information about the Haskell-Cafe mailing list