On Mar 8, 2006, at 1:29 PM, zell_ffhut wrote:
Im afraid im baffled again!
Im now trying to add a char to a string of strings (eg - ["434233434"
"444929192" "909313434"]
Im sure i can use my previous function to help me achive this, but
i can't
seem to get it workinging
charToGrid :: Char -> Position -> Grid -> Grid
charToGrid c (row,col) g = concat g (changeValue c(row*9 + col))
Im not sure i should be using concat, as i have to return a grid as
it was
given, just with the added char.
As before, the idea is to create a new list with the changes you
want, only now you have a list "two levels deep". So the first thing
to do is to pick out the sublist (row) you want to "change" and
create a new changed sublist (row), and then rebuild your grid. Try
this, it may get you started:
updateList :: (a -> a) -> Int -> [a] -> [a]
updateList f i l = begin ++ (f x : end)
where (begin, x : end) = splitAt i l
BTW, lists aren't very good for these kinds of manipulations. If you
really need an indexable, mutable data structure, try one of
Data.Array.*
Rob Dockins
Speak softly and drive a Sherman tank.
Laugh hard; it's a long way to the bank.
-- TMBG
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe