Re: [Haskell-cafe] Template Haskell vs Rewrite Rules?
I once experimented with something similar. This is a preprocessor. This was a long time ago, and I don't use it. https://patch-tag.com/r/jmcarthur/overloaded-whitespace/snapshot/current/content/pretty/Main.hs On Thu, Apr 19, 2012 at 8:40 AM, Ismael Figueroa Palet wrote: > Hi Michael! > > Thanks (again) for your answer. > I'm not quite confident using TH yet, but it seems in your code you must > define an 'app' function, and then use [overloadedApp|... |] as a > quasiquoteator to inject the overloaded app, right? > > Thanks for the zeroth reference too, one question remains for me: what are > the constrasts/differences between TH and RewriteRules? :-) > > > 2012/4/19 Michael Sloan >> >> You're in luck! This is something I've wanted to implement before in >> the past, and your email reminded me. While pretty awful, it could be >> used for doing some interesting value-interception instrumentation in >> Haskell. Recently I've been messing with TH a lot, so this initial >> implementation was rather straightforward. >> >> >> https://github.com/mgsloan/overload-app/blob/master/src/Language/Haskell/TH/OverloadApp.hs >> >> Usage: >> https://github.com/mgsloan/overload-app/blob/master/examples/Example1.hs >> >> Note: Relatively untested implementation, let me know if you find any >> problems! >> >> It only does this transformation to direct function application, >> unfortunately. In order to properly overload apply for infix >> operators, you'll need to be able to resolve fixities at compile time. >> This could be done by using the code in >> http://hackage.haskell.org/trac/haskell-prime/wiki/FixityResolution >> and using the fixity information yielded by TH's "reify". Someone >> aught to have done this before, but I haven't seen it. >> >> Handling the applications involved in do-notation, comprehensions, >> enumerations, and anything else that's such direct syntax sugar would >> also be a bit of work (but could be very useful for other TH >> quasiquoting stuff!). >> >> You might also be interested in this: >> >> http://hackage.haskell.org/package/zeroth-2009.6.23.3 >> >> Hope that helps! >> >> -Michael Sloan >> >> On Wed, Apr 18, 2012 at 9:49 AM, Ismael Figueroa Palet >> wrote: >> > I'm working on getting annotated versions of all instances of a function >> > of >> > a typeclass, and was wondering what are the relation/differences between >> > Template Haskell and the Rewrite Rules section. Of course this is >> > specific >> > to GHC. >> > >> > Another question, in Racket, primitive function application is denoted >> > #%app. And using macros I can re-export #%app to be a different function >> > f, >> > so a program: >> > >> > (g a) is rewritten into (f g a) >> > >> > is there a way to do the same thing using TH or Rewrite Rules? >> > >> > Thanks >> > >> > -- >> > Ismael >> > >> > >> > ___ >> > Haskell-Cafe mailing list >> > Haskell-Cafe@haskell.org >> > http://www.haskell.org/mailman/listinfo/haskell-cafe >> > > > > > > -- > Ismael > > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell vs Rewrite Rules?
Hi Michael! Thanks (again) for your answer. I'm not quite confident using TH yet, but it seems in your code you must define an 'app' function, and then use [overloadedApp|... |] as a quasiquoteator to inject the overloaded app, right? Thanks for the zeroth reference too, one question remains for me: what are the constrasts/differences between TH and RewriteRules? :-) 2012/4/19 Michael Sloan > You're in luck! This is something I've wanted to implement before in > the past, and your email reminded me. While pretty awful, it could be > used for doing some interesting value-interception instrumentation in > Haskell. Recently I've been messing with TH a lot, so this initial > implementation was rather straightforward. > > > https://github.com/mgsloan/overload-app/blob/master/src/Language/Haskell/TH/OverloadApp.hs > > Usage: > https://github.com/mgsloan/overload-app/blob/master/examples/Example1.hs > > Note: Relatively untested implementation, let me know if you find any > problems! > > It only does this transformation to direct function application, > unfortunately. In order to properly overload apply for infix > operators, you'll need to be able to resolve fixities at compile time. > This could be done by using the code in > http://hackage.haskell.org/trac/haskell-prime/wiki/FixityResolution > and using the fixity information yielded by TH's "reify". Someone > aught to have done this before, but I haven't seen it. > > Handling the applications involved in do-notation, comprehensions, > enumerations, and anything else that's such direct syntax sugar would > also be a bit of work (but could be very useful for other TH > quasiquoting stuff!). > > You might also be interested in this: > > http://hackage.haskell.org/package/zeroth-2009.6.23.3 > > Hope that helps! > > -Michael Sloan > > On Wed, Apr 18, 2012 at 9:49 AM, Ismael Figueroa Palet > wrote: > > I'm working on getting annotated versions of all instances of a function > of > > a typeclass, and was wondering what are the relation/differences between > > Template Haskell and the Rewrite Rules section. Of course this is > specific > > to GHC. > > > > Another question, in Racket, primitive function application is denoted > > #%app. And using macros I can re-export #%app to be a different function > f, > > so a program: > > > > (g a) is rewritten into (f g a) > > > > is there a way to do the same thing using TH or Rewrite Rules? > > > > Thanks > > > > -- > > Ismael > > > > > > ___ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > -- Ismael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell vs Rewrite Rules?
You're in luck! This is something I've wanted to implement before in the past, and your email reminded me. While pretty awful, it could be used for doing some interesting value-interception instrumentation in Haskell. Recently I've been messing with TH a lot, so this initial implementation was rather straightforward. https://github.com/mgsloan/overload-app/blob/master/src/Language/Haskell/TH/OverloadApp.hs Usage: https://github.com/mgsloan/overload-app/blob/master/examples/Example1.hs Note: Relatively untested implementation, let me know if you find any problems! It only does this transformation to direct function application, unfortunately. In order to properly overload apply for infix operators, you'll need to be able to resolve fixities at compile time. This could be done by using the code in http://hackage.haskell.org/trac/haskell-prime/wiki/FixityResolution and using the fixity information yielded by TH's "reify". Someone aught to have done this before, but I haven't seen it. Handling the applications involved in do-notation, comprehensions, enumerations, and anything else that's such direct syntax sugar would also be a bit of work (but could be very useful for other TH quasiquoting stuff!). You might also be interested in this: http://hackage.haskell.org/package/zeroth-2009.6.23.3 Hope that helps! -Michael Sloan On Wed, Apr 18, 2012 at 9:49 AM, Ismael Figueroa Palet wrote: > I'm working on getting annotated versions of all instances of a function of > a typeclass, and was wondering what are the relation/differences between > Template Haskell and the Rewrite Rules section. Of course this is specific > to GHC. > > Another question, in Racket, primitive function application is denoted > #%app. And using macros I can re-export #%app to be a different function f, > so a program: > > (g a) is rewritten into (f g a) > > is there a way to do the same thing using TH or Rewrite Rules? > > Thanks > > -- > Ismael > > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Template Haskell vs Rewrite Rules?
I'm working on getting annotated versions of all instances of a function of a typeclass, and was wondering what are the relation/differences between Template Haskell and the Rewrite Rules section. Of course this is specific to GHC. Another question, in Racket, primitive function application is denoted #%app. And using macros I can re-export #%app to be a different function f, so a program: (g a) is rewritten into (f g a) is there a way to do the same thing using TH or Rewrite Rules? Thanks -- Ismael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe