Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-20 Thread C K Kashyap
Thanks Aditya...I think that is what I am looking for. On Mon, Jul 19, 2010 at 10:40 PM, aditya siram aditya.si...@gmail.comwrote: Sorry, the previous code does not compile. It should be: replace :: Int - [IORef (Int,Int,Int)] - (Int,Int,Int) - IO () replace index pixels new_val = do

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread Ketil Malde
C K Kashyap ckkash...@gmail.com writes: I looked at State Monad yesterday and this question popped into my mind. From what I gather State Monad essentially allows the use of Haskell's do notation to invisibly pass around a state. So, does the use of Monadic style fetch us more than syntactic

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread C K Kashyap
Okay...I think I am beginning to understand. Is it right to assume that magic is backed by FFI and cannot be done in pure Haskell? On Mon, Jul 19, 2010 at 1:47 PM, Ketil Malde ke...@malde.org wrote: C K Kashyap ckkash...@gmail.com writes: I looked at State Monad yesterday and this question

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread C K Kashyap
Also, Claude ... If I am correct, in your example, there is no in-place replacement happening. On Mon, Jul 19, 2010 at 2:36 PM, C K Kashyap ckkash...@gmail.com wrote: Okay...I think I am beginning to understand. Is it right to assume that magic is backed by FFI and cannot be done in pure

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread Max Rabkin
On Mon, Jul 19, 2010 at 10:17 AM, Ketil Malde ke...@malde.org wrote: At it's heart, monads are just syntactic convenience, but like many other syntactic conveniences, allows you to structure your code better. Thus it's more about programmer efficiency than program efficiency. (The do notation

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread aditya siram
Do you want a solution like this? import Data.IORef replace :: Int - [IORef (Int,Int,Int)] - (Int,Int,Int) - IO () replace index pixels new_val = do old_val - return $ pixels !! index writeIORef old_val new_val print_pixels = mapM (\p - readIORef p = print) test_data :: [(Int,Int,Int)]

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread aditya siram
Sorry, the previous code does not compile. It should be: replace :: Int - [IORef (Int,Int,Int)] - (Int,Int,Int) - IO () replace index pixels new_val = do old_val - return $ pixels !! index writeIORef old_val new_val print_pixels = mapM_ (\p - readIORef p = print) test_data :: [(Int,Int,Int)]

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-16 Thread C K Kashyap
Thanks Wren, Thanks Dave ... a quick question though could you point me to an example where I could build up my own in place modifiable data structure in Haskell without using any standard library stuff? For example, if I wanted an image representation such as this [[(Int,Int.Int)]] - basically

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-16 Thread Claude Heiland-Allen
Hi, 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

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-16 Thread C K Kashyap
Hi Claude, 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

[Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread C K Kashyap
Hi, I looked at State Monad yesterday and this question popped into my mind. From what I gather State Monad essentially allows the use of Haskell's do notation to invisibly pass around a state. So, does the use of Monadic style fetch us more than syntactic convenience? Again, if I understand

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread Daniel Fischer
On Thursday 15 July 2010 18:02:47, C K Kashyap wrote: Hi, I looked at State Monad yesterday and this question popped into my mind. From what I gather State Monad essentially allows the use of Haskell's do notation to invisibly pass around a state. So, does the use of Monadic style fetch

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread David Leimbach
On Thu, Jul 15, 2010 at 9:02 AM, C K Kashyap ckkash...@gmail.com wrote: Hi, I looked at State Monad yesterday and this question popped into my mind. From what I gather State Monad essentially allows the use of Haskell's do notation to invisibly pass around a state. So, does the use of Monadic

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread C K Kashyap
Thanks Daniel, Better refactorability. If you're using monadic style, changing from, say, State Thing to StateT Thing OtherMonad or from StateT Thing FirstMonad to StateT Thing SecondMonad typically requires only few changes. Explicit state-passing usually requires more changes. So,

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread C K Kashyap
Thanks David for the detailed explanation. A couple of quick clarifications - 1. Even the invisible state that gets modified during the monadic evaluation is referred to as side effect right? 2. I am a little unclear about in-place - does pure Haskell let one do such a thing- or does it need

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread David Leimbach
On Thu, Jul 15, 2010 at 10:34 AM, C K Kashyap ckkash...@gmail.com wrote: Thanks David for the detailed explanation. A couple of quick clarifications - 1. Even the invisible state that gets modified during the monadic evaluation is referred to as side effect right? If the state is free of

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread wren ng thornton
C K Kashyap wrote: Thanks Daniel, Better refactorability. If you're using monadic style, changing from, say, State Thing to StateT Thing OtherMonad or from StateT Thing FirstMonad to StateT Thing SecondMonad typically requires only few changes. Explicit state-passing usually requires more