<[EMAIL PROTECTED]> wrote:

> Hi I have a bit of a dilemma.I have a list of lists, eg,
> [[1,2,3],[4,5,6],[7,8,9]]. Imagine they represent a grid with 0-2 on
> the x axis and 0-2 on the y axis, eg, (0,0) is 1, (1,0) is 2, (2,1)
> is 6, etc and (2,3) is 9. I want to be able to put in the list of
> lists, and the (x,y) coordinate, and return the value. 
> 
select x y ys = (ys !! y) !! x


> Also, I need to be able to replace a value in the list. Eg, if I
> wanted to replace (2,3) with 100, then the output of the expression
> would be [[1,2,3],[4,5,6],[7,8,100]].
>
you can't replace it, you can only construct a new list: Your function
will likely be of the type

replace :: Int -> Int -> a -> [[a]] -> [[a]]

I won't give the answer here, as that would spoil all of the fun
and delight you'll have while browsing through the Prelude and
Data.List and see how much duct tape there's around, waiting to be
used, plus I'd have to open a new file as ghci doesn't support
multi-line functions.

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to