Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
Stefan, Data.Derive is a most awesome piece of code! Is there soemething in DrIFT that you did not like that made you write it? Thanks a lot! On Apr 5, 2007, at 12:48 AM, Stefan O'Rear wrote: Data.Derive can do this. In an attempt to avoid munging the relevent files they are

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
Stefan, What version of ghc are you using? Mine is 6.6. Data/Derive/Play.hs:9:7: Could not find module `Control.Monad.State': it is a member of package mtl-1.0, which is hidden I commented out that import line. Preprocessing library derive-0.1... Preprocessing executables for

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
On Apr 5, 2007, at 11:04 AM, Joel Reymont wrote: This is in Language.Haskell.TH.Syntax which is imported at the top of Data/Derive/TH.hs so I don't understand the cause of the error Apparently instance Functor Q was added to 6.6 very recently and it's not in MacPorts yet. I decided to

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
That did it, thanks! On Apr 5, 2007, at 12:07 PM, Twan van Laarhoven wrote: instance Functor Q where fmap = liftM -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Twan van Laarhoven
Joel Reymont wrote: This is in Language.Haskell.TH.Syntax which is imported at the top of Data/Derive/TH.hs so I don't understand the cause of the error instance Functor Q where fmap f (Q x) = Q (fmap f x) ... Any suggestions? Since Q is a Monad, you can make the instance instance

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
This is in Language.Haskell.TH.Syntax which is imported at the top of Data/Derive/TH.hs so I don't understand the cause of the error instance Functor Q where fmap f (Q x) = Q (fmap f x) Copying the above into TH.hs gives me Preprocessing library derive-0.1... Preprocessing executables for

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Jules Bean
Joel Reymont wrote: Folks, I have very uniform Parsec code like this and I'm wondering if I can derive it using TemplateHaskell or DrIFT or some other tool. Any ideas? Others have given good answers on how to use code-generation. I am more interested in whether code generation is actually

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Jules Bean
Jules Bean wrote: data paramType = JNum | JBool | JStr paramParser JNum = numExpr paramParser JBool = boolExpr paramParser JStr = strExpr unary x pt = reserved (quasiShow (x undefined)) parens (paramParser pt) = return . x strCall = choice ( map unary

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
With derive compiled and installed I thought I would change the code a bit and try it... ghci -fth -v0 -e '$( _derive_print_instance makeFunParser Foo )' baz.hs baz.hs:30:3: Not in scope: `a1' Any help is appreciated! Thanks, Joel --- FunParser.hs: module FunParser where

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
Here's the output from -ddump-splices (thanks Saizan for the tip). It's returning a1 instead of a0. ghci -fth -e '$( _derive_print_instance makeFunParser Foo )' baz.hs -ddump-splices baz.hs:1:0: baz.hs:1:0: Splicing declarations derive makeFunParser 'Foo ==

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Stefan O'Rear
On Thu, Apr 05, 2007 at 02:47:21PM +0100, Joel Reymont wrote: Here's the output from -ddump-splices (thanks Saizan for the tip). It's returning a1 instead of a0. ghci -fth -e '$( _derive_print_instance makeFunParser Foo )' baz.hs -ddump-splices baz.hs:1:0: baz.hs:1:0: Splicing

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Stefan O'Rear
On Thu, Apr 05, 2007 at 03:19:15PM +0100, Joel Reymont wrote: numExpr :: GenParser Char a NumExpr numExpr = choice [ integer = return . Int , float = return . Num ] Parsec's choice operator works by parsing the first, and only parsing the second if the first fails

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
Shouldn't this work just as well? numExpr = choice [ try $ float = return . Num , integer = return . Int ] It works on Foo(10.345) but not on Bar(10, 103.34). On Apr 5, 2007, at 4:09 PM, Stefan O'Rear wrote: numExpr :: GenParser Char a NumExpr numExpr = do sg -

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread John Meacham
On Wed, Apr 04, 2007 at 04:48:56PM -0700, Stefan O'Rear wrote: Data.Derive can do this. In an attempt to avoid munging the relevent files they are attached. You might want to note that DrIFT used to be called derive before it (amicably) changed its name due to a conflict with a product of the

Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-04 Thread Stefan O'Rear
On Thu, Apr 05, 2007 at 12:14:52AM +0100, Joel Reymont wrote: Folks, I have very uniform Parsec code like this and I'm wondering if I can derive it using TemplateHaskell or DrIFT or some other tool. Any ideas? Note that 1) The reserved word matches the constructor 2) No arguments