Re: [Haskell-cafe] Using multiplate to get free variables from a syntax tree

2012-02-26 Thread Matt Brown
Thanks everyone! This has been interesting and helpful. I for one had not seen multirec, but will check it out. Is the implication that multirec is more or less complicated than multiplate? Cheers, -matt On Sun, Feb 26, 2012 at 3:28 PM, Sjoerd Visscher wrote: > Here's the same code but with a

Re: [Haskell-cafe] Using multiplate to get free variables from a syntax tree

2012-02-26 Thread Sjoerd Visscher
Here's the same code but with a variation on Multiplate that doesn't use records, but a GADT: https://gist.github.com/1919528 It is easier on the eyes I think, but probably not any easier to decipher. But hey, this is generic programming for mutually recursive datatypes, that's a complicated su

Re: [Haskell-cafe] Using multiplate to get free variables from a syntax tree

2012-02-25 Thread Thomas Schilling
No that's correct. I have to say the multiplate code is incredibly hard to decipher. On 25 February 2012 19:47, Sjoerd Visscher wrote: > I don't understand what you mean. > ($[]) . foldFor expr freeVariablesPlate $ Add (Let ("x" := Con 1) (Add (EVar "x") (EVar "y"))) (EVar "x") > (["y

Re: [Haskell-cafe] Using multiplate to get free variables from a syntax tree

2012-02-25 Thread Sjoerd Visscher
I don't understand what you mean. >>> ($[]) . foldFor expr freeVariablesPlate $ Add (Let ("x" := Con 1) (Add >>> (EVar "x") (EVar "y"))) (EVar "x") (["y","x"],[]) I.e. free variables y and x, no bound variables. Is that not correct? Sjoerd On Feb 25, 2012, at 7:15 PM, Thomas Schilling wrote:

Re: [Haskell-cafe] Using multiplate to get free variables from a syntax tree

2012-02-25 Thread Thomas Schilling
That will give you the wrong answer for an expression like: (let x = 1 in x + y) + x Unless you do a renaming pass first, you will end up both with a bound "x" and a free "x". On 25 February 2012 16:29, Sjoerd Visscher wrote: > > On Feb 24, 2012, at 10:09 PM, Stephen Tetley wrote: > >> I'm no

Re: [Haskell-cafe] Using multiplate to get free variables from a syntax tree

2012-02-25 Thread Sjoerd Visscher
On Feb 24, 2012, at 10:09 PM, Stephen Tetley wrote: > I'm not familiar with Multiplate either, but presumably you can > descend into the decl - collect the bound vars, then descend into the > body expr. > Naturally you would need a monadic traversal > rather than an applicative one... It turn

Re: [Haskell-cafe] Using multiplate to get free variables from a syntax tree

2012-02-24 Thread Stephen Tetley
I'm not familiar with Multiplate either, but presumably you can descend into the decl - collect the bound vars, then descend into the body expr. > Let <$> decl child d <*> expr child e This seems like a common traversal that Strafunski would handle, and with Multiplate being a competitor / succe

Re: [Haskell-cafe] Using multiplate to get free variables from a syntax tree

2012-02-24 Thread Brent Yorgey
On Thu, Feb 23, 2012 at 01:18:22PM -0800, Matt Brown wrote: > Hi all, > > I'm reading the haskellwiki article on multiplate. Is it possible to > modify the getVariablesPlate example to return the free variables? > One idea I had is to store an environment in a reader monad, and use > local to upda

[Haskell-cafe] Using multiplate to get free variables from a syntax tree

2012-02-23 Thread Matt Brown
Hi all, I'm reading the haskellwiki article on multiplate. Is it possible to modify the getVariablesPlate example to return the free variables? One idea I had is to store an environment in a reader monad, and use local to update the environment at a let expression. Couldn't figure it out, though.