[Haskell-cafe] A question about State Monad and Monad in general
C K Kashyap
ckkashyap at gmail.com
Fri Jul 16 06:40:03 EDT 2010
Thanks a lot for the example.
Btw, is this where you are trying in-place replacement?
modifyAtIndex :: (a -> a) -> Nat -> List a -> List a
modifyAtIndex f i as =
let ias = zip nats as
g (Tuple2 j a) = case i `eq` j of
False -> a
True -> f a
in map g ias
modifyAtIndex2 :: (a -> a) -> Nat -> Nat -> List (List a) -> List (List a)
modifyAtIndex2 f i j = modifyAtIndex (modifyAtIndex f i) j
Doesn't modfiyAtIndex return a new list?
On Fri, Jul 16, 2010 at 2:28 PM, Claude Heiland-Allen <
claudiusmaximus at goto10.org> wrote:
> On 16/07/10 07:35, C K Kashyap wrote:
>> Haskell without using any standard library stuff?
> For example, if I wanted an image representation such as this
>> [[(Int,Int.Int)]] - basically a list of lists of 3 tuples (rgb) and
>> wanted to do in place replacement to set the pixel values, how could I
>> go about it.
> Break the problem down into parts:
> 1. replace a single pixel
> 2. modify an element in a list at a given index using a
> given modification function
> 3. modify an element in a list of lists at a pair of given
> indices using a given replacement function
> I had a stab at it. Without any standard library stuff I couldn't figure
> out how to print any output, though - so who knows if the code I wrote does
> what I intended.
> The point is, it's libraries all the way down - so use them, study them
> where necessary for understanding, and write them and share them when you
> find something missing.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe