Re: [Haskell-cafe] Transformation sequence

2007-10-22 Thread R Hayes
I know that this is a resolved question, but wouldn't Huet's Zipper also work for this On Oct 20, 2007, at 5:26 PM, Alfonso Acosta wrote: On 10/20/07, Mads Lindstrøm [EMAIL PROTECTED] wrote: I am not a monad-expect, so I may be wrong, but wouldn't a writer monad be more appropriate?

[Haskell-cafe] Transformation sequence

2007-10-20 Thread Andrew Coppin
I'm writing some code where I take an expression tree and transform it into another equivilent one. Now it's moderately easy to write the code that does the transformation. But what I *really* want is to print out the transformation *sequence*. This appears to be much more awkward. What I

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Alfonso Acosta
How about using a state monad as a logger? You store the transformation sequence in the state while processing the tree, then you simply retrieve the state and print it out. Your transformation function should change to import Control.Monad.State data Log = ... -- to be defined type

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Andrew Coppin
Alfonso Acosta wrote: How about using a state monad as a logger? You store the transformation sequence in the state while processing the tree, then you simply retrieve the state and print it out. Mmm... that could work... I'll investigate. Thanks.

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Twan van Laarhoven
Andrew Coppin wrote: I'm writing some code where I take an expression tree and transform it into another equivilent one. Now it's moderately easy to write the code that does the transformation. But what I *really* want is to print out the transformation *sequence*. This appears to be much

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Mads Lindstrøm
Hi Alfonso Andrew Alfonso Acosta wrote: How about using a state monad as a logger? I am not a monad-expect, so I may be wrong, but wouldn't a writer monad be more appropriate? After all, it is just used for logging the intermediate results, not to keep read/write state. In other words, we just

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Brent Yorgey
On 10/20/07, Andrew Coppin [EMAIL PROTECTED] wrote: I'm writing some code where I take an expression tree and transform it into another equivilent one. Now it's moderately easy to write the code that does the transformation. But what I *really* want is to print out the transformation

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Andrew Coppin
Twan van Laarhoven wrote: How about: transform ... = (transform sub1 = put back into main expression) ++ (transform sub2 = put back into main expression) Or something to that effect? Or maybe transform ... = do sub' - transform sub1 ++ transform sub2 put back

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Andrew Coppin
Brent Yorgey wrote: Hmm... I'm having trouble understanding exactly what you want. In particular, I don't understand what this statement: But what I *really* want is to print out the transformation *sequence*. has to do with the pseudocode that you exhibit later. Could you perhaps

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Brandon S. Allbery KF8NH
On Oct 20, 2007, at 15:05 , Andrew Coppin wrote: I can quite happily construct a program which, given the first line, yields the last line. But getting it to print all the intermediate steps is harder. And, like I said, when something is hard in Haskell, it usually means you're doing it

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Stefan O'Rear
On Sat, Oct 20, 2007 at 08:05:37PM +0100, Andrew Coppin wrote: Brent Yorgey wrote: Hmm... I'm having trouble understanding exactly what you want. In particular, I don't understand what this statement: But what I *really* want is to print out the transformation *sequence*. has to do with

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Andrew Coppin
Stefan O'Rear wrote: On Sat, Oct 20, 2007 at 08:05:37PM +0100, Andrew Coppin wrote: I want to construct a program that prints out something like this: [\fx - f(fx)] [\f - [\x - f(fx)]] [\f - S[\x - f][\x - fx]] [\f - S(Kf)[\x - fx]] [\f - S(Kf)f] S[\f - S(Kf)][\f - f] S(S[\f - S][\f -

Re: [Haskell-cafe] Transformation sequence

2007-10-20 Thread Alfonso Acosta
On 10/20/07, Mads Lindstrøm [EMAIL PROTECTED] wrote: I am not a monad-expect, so I may be wrong, but wouldn't a writer monad be more appropriate? You are at least more monad-expert than myself . I knew the existence of the writer monad but not really how it works. After checking its