Re: [Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-15 Thread Malcolm Wallace
That's what I had originally. However, some people have made critical comments about CPP macros on this list and I thought that TH was considered the better option. I was one of those people advising against the use of CPP macros. However, Template Haskell is ghc-only, and is unlikely ever

[Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-15 Thread Kevin Jardine
Hi Malcolm, In this case, I am counting on GHC's {-# LANGUAGE GeneralizedNewtypeDeriving #-} feature to derive the instances for the classes I am including in the deriving clause. So perhaps portability is not a big issue here in any case. I do think that defObj(MyType) looks a bit cleaner

Re: [Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-15 Thread Ben Millwood
On Wed, Sep 15, 2010 at 2:11 PM, Kevin Jardine kevinjard...@gmail.com wrote: I do think that defObj(MyType) looks a bit cleaner than $(defObj MyType) I believe as of GHC 6.12 you no longer need the $() around top-level splices. So that would just be: defObj MyType

[Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-15 Thread Kevin Jardine
Hi Ben, Good point! I can confirm that it does compile under GHC 6.12. So really the same number of characters either way. Kevin On Sep 15, 4:49 pm, Ben Millwood hask...@benmachine.co.uk wrote: On Wed, Sep 15, 2010 at 2:11 PM, Kevin Jardine kevinjard...@gmail.com wrote: I do think that

Re: [Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-15 Thread Gregory Crosswhite
On 9/15/10 1:31 AM, Malcolm Wallace wrote: [...] However, Template Haskell is ghc-only, and is unlikely ever to be implemented by any other Haskell compiler. [...] Could it be implemented as a separate preprocessor? Cheers, Greg ___ Haskell-Cafe

Re: [Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-15 Thread Antoine Latter
It has been - there is a package called 'zeroth' on hackage. It only works for top-level splices, the last I looked. On Sep 15, 2010 11:20 AM, Gregory Crosswhite gcr...@phys.washington.edu wrote: On 9/15/10 1:31 AM, Malcolm Wallace wrote: [...] However, Template Haskell is ghc-only, and is

Re: [Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-15 Thread wren ng thornton
On 9/15/10 9:11 AM, Kevin Jardine wrote: Hi Malcolm, In this case, I am counting on GHC's {-# LANGUAGE GeneralizedNewtypeDeriving #-} feature to derive the instances for the classes I am including in the deriving clause. So perhaps portability is not a big issue here in any case. Yes, but

[Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-14 Thread Kevin Jardine
I supposed the simple solution might be CPP: #define defObj(NAME) newtype NAME = NAME Obj deriving (A,B,C,D) and then use defObj (MyType) I have heard some people, however, say that CPP macros are horrible in Haskell, so is there a better solution? Kevin On Sep 14, 10:34 am, Miguel

[Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-14 Thread Kevin Jardine
Thanks Serguey! The library code compiles, but when I try to use it in client code: a. I get: Not in scope: type constructor or class 'A' and even stranger, b. GHC cannot find any of my code after the $(mkNewType A) and claims that all the functions I defined there are also not in scope.

[Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-14 Thread Kevin Jardine
Hmm - It seems to work if the code is defined before my main function and not after it. Does this have to do with TH being part of the compile process and so the order matters? Kevin On Sep 14, 6:03 pm, Kevin Jardine kevinjard...@gmail.com wrote: Thanks Serguey! The library code compiles,

Re: [Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-14 Thread Erik Hesselink
Yes, if you use template haskell, all top level functions and values have to be defined before you use them. Erik On Tue, Sep 14, 2010 at 18:11, Kevin Jardine kevinjard...@gmail.com wrote: Hmm - It seems to work if the code is defined before my main function and not after it. Does this have

[Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-14 Thread Kevin Jardine
OK, thanks for everyone's help! Serguey's code works very well now. Kevin On Sep 14, 6:14 pm, Erik Hesselink hessel...@gmail.com wrote: Yes, if you use template haskell, all top level functions and values have to be defined before you use them. Erik On Tue, Sep 14, 2010 at 18:11, Kevin

[Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-14 Thread Kevin Jardine
Hi John, That's what I had originally. However, some people have made critical comments about CPP macros on this list and I thought that TH was considered the better option. What do other people think? Serguey's code is great in any case as it gives me a clearer understanding on how TH works.