Proposal for stand-alone deriving declarations?
On http://hackage.haskell.org/trac/haskell-prime/wiki/ DerivedInstances it says: - There is no way to derive an instance of a class for a data type that is defined elsewhere (in another module). Though there is no proposal to fix this. Would such a proposal be appropriate for Haskell'? If so, I propose to add a top-level declaration on the form: 'deriving' qtycls 'for' qtycon which produces the same instance as a deriving clause in the declaration of the datatype or newtype would. I have recently (thanks to the GHC Hackathon) implemented this in GHC. /Björn ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
RE: Proposal for stand-alone deriving declarations?
Thanks for doing this. Is this the syntax we settled on? I remember we discussed it at some length S | -Original Message- | From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of | Bjorn Bringert | Sent: 05 October 2006 09:05 | To: haskell-prime@haskell.org | Subject: Proposal for stand-alone deriving declarations? | | On http://hackage.haskell.org/trac/haskell-prime/wiki/ | DerivedInstances it says: | | - There is no way to derive an instance of a class for a data type | that is defined elsewhere (in another module). | | Though there is no proposal to fix this. Would such a proposal be | appropriate for Haskell'? | | | If so, I propose to add a top-level declaration on the form: | | 'deriving' qtycls 'for' qtycon | | which produces the same instance as a deriving clause in the | declaration of the datatype or newtype would. | | | I have recently (thanks to the GHC Hackathon) implemented this in GHC. | | /Björn | | ___ | Haskell-prime mailing list | Haskell-prime@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-prime ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
Re: Proposal for stand-alone deriving declarations?
Bjorn Bringert: On http://hackage.haskell.org/trac/haskell-prime/wiki/ DerivedInstances it says: - There is no way to derive an instance of a class for a data type that is defined elsewhere (in another module). Though there is no proposal to fix this. Would such a proposal be appropriate for Haskell'? I think this would be a useful feature to have. (I certainly wished to have independent deriving declarations many times when writing Haskell code.) It also seems to be a fairly small, well understood extension. If so, I propose to add a top-level declaration on the form: 'deriving' qtycls 'for' qtycon which produces the same instance as a deriving clause in the declaration of the datatype or newtype would. I guess, the right way to go about this would be to say that independent deriving declarations are the fundamental way of deriving a type class. The original form of a deriving clause at a data/newtype declaration is, then, just a syntactic shorthand for a data/newtype declaration plus a bunch of independent deriving declarations. What is not so nice is that you take a new keyword ('for'), which is quite likely to have been used as a variable name in existing code. (Or does it work out to use one of the 'special' names here?) I think it would be useful to write the proposal in complete detail up on the Haskell' wiki. Manuel ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
Re: Proposal for stand-alone deriving declarations?
What I implemented in GHC is an extension of the proposal below. The proposal just mentions: deriving Class for Type In GHC I also added a form for newtype deriving of multi-parameter type classes: deriving (Class t1 ... tn) for Type I think that it's close to what we ended up with when talking about it at the Hackathon. My intuition about this syntax is that except for the for Type part, it looks the same as a normal deriving clause. The for part is just there to connect it to a data/newtype declaration. This lets it pretty much use the normal code for deriving declarations. Stand-alone deriving declarations are currently a little bit weaker than normal deriving clauses, since the current implementation does not let you reference the type arguments of a newtype in the arguments of an MPTC. See my response to Bulat on [EMAIL PROTECTED] for more details. /Björn On 5 okt 2006, at 10.36, Simon Peyton-Jones wrote: Thanks for doing this. Is this the syntax we settled on? I remember we discussed it at some length S | -Original Message- | From: [EMAIL PROTECTED] [mailto:haskell-prime- [EMAIL PROTECTED] On Behalf Of | Bjorn Bringert | Sent: 05 October 2006 09:05 | To: haskell-prime@haskell.org | Subject: Proposal for stand-alone deriving declarations? | | On http://hackage.haskell.org/trac/haskell-prime/wiki/ | DerivedInstances it says: | | - There is no way to derive an instance of a class for a data type | that is defined elsewhere (in another module). | | Though there is no proposal to fix this. Would such a proposal be | appropriate for Haskell'? | | | If so, I propose to add a top-level declaration on the form: | | 'deriving' qtycls 'for' qtycon | | which produces the same instance as a deriving clause in the | declaration of the datatype or newtype would. | | | I have recently (thanks to the GHC Hackathon) implemented this in GHC. | | /Björn | | ___ | Haskell-prime mailing list | Haskell-prime@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-prime ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
RE: Proposal for stand-alone deriving declarations?
| What is not so nice is that you take a new keyword ('for'), which is | quite likely to have been used as a variable name in existing code. (Or | does it work out to use one of the 'special' names here?) The latter is what Bjorn has done. That is, 'for' is only special in this one context. You can use it freely otherwise. As I understand it anyway. | I think it would be useful to write the proposal in complete detail up | on the Haskell' wiki. Yes please. Bjorn? (It may just be a qn of transcribing the user manual stuff you have written.) S ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
Re: Proposal for stand-alone deriving declarations?
Simon Peyton-Jones wrote: | What is not so nice is that you take a new keyword ('for'), which is | quite likely to have been used as a variable name in existing code. (Or | does it work out to use one of the 'special' names here?) The latter is what Bjorn has done. That is, 'for' is only special in this one context. You can use it freely otherwise. As I understand it anyway. Yes. There is even a for function somewhere in the libraries (or was it the testsuite, can't remeber), which tripped up one of my early versions, before I had remembered to make for as a special ID in the parser. | I think it would be useful to write the proposal in complete detail up | on the Haskell' wiki. Yes please. Bjorn? (It may just be a qn of transcribing the user manual stuff you have written.) Sure. It seems that I have to be on the committee to write to the Wiki. Can I join it? /Björn ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
Re: Proposal for stand-alone deriving declarations?
Hello, A question about the syntax: would there be a problem if we made the 'deriving' declaration look like an instance? Then we would not need the special identifier 'for', and also we have a more standard looking notation. I am thinking something like: deriving Show SomeType deriving Eq (AnotherType a) -Iavor On 10/5/06, Björn Bringert [EMAIL PROTECTED] wrote: Simon Peyton-Jones wrote: | What is not so nice is that you take a new keyword ('for'), which is | quite likely to have been used as a variable name in existing code. (Or | does it work out to use one of the 'special' names here?) The latter is what Bjorn has done. That is, 'for' is only special in this one context. You can use it freely otherwise. As I understand it anyway. Yes. There is even a for function somewhere in the libraries (or was it the testsuite, can't remeber), which tripped up one of my early versions, before I had remembered to make for as a special ID in the parser. | I think it would be useful to write the proposal in complete detail up | on the Haskell' wiki. Yes please. Bjorn? (It may just be a qn of transcribing the user manual stuff you have written.) Sure. It seems that I have to be on the committee to write to the Wiki. Can I join it? /Björn ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
Re: Proposal for stand-alone deriving declarations?
We considered that syntax, but decided against it. Stand-alone deriving declarations are made to be as similar as possible to the current deriving mechanism, rather than be similar to instance declarations. The basic reason for maintaining a syntactic distinction between instance declarations and deriving declarations is to make the programmer aware of the restrictions of the deriving mechanism. These are some things that make deriving declarations different from instance declarations: - You can only derive instances for data types and newtypes. - For deriving declarations, the compiler figures out the constraints, whereas the programmer writes them for instance declarations. - In GHC, you can declare non-Haskell98 instances such as Eq (C X) where X is a concrete type, but you can't do deriving for them. - When deriving instances of multi-parameter type classes (again non- standard), the newtype for which the deriving is made must be the last argument to the class. If the syntax were deriving (Class T1 ... Tn), it might not be clear to the reader what type the deriving is for. I can't see any technical reason not to do as you propose. One advantage would be that it makes it possible to fully subsume GHC's current deriving extensions (though there are other ways to do this, see my recent e-mail to ghc-cvs). One slight disadvantage is that it does require a bit more footwork in the compiler to figure out which type to do the deriving for. /Björn On 5 okt 2006, at 19.58, Iavor Diatchki wrote: Hello, A question about the syntax: would there be a problem if we made the 'deriving' declaration look like an instance? Then we would not need the special identifier 'for', and also we have a more standard looking notation. I am thinking something like: deriving Show SomeType deriving Eq (AnotherType a) -Iavor On 10/5/06, Björn Bringert [EMAIL PROTECTED] wrote: Simon Peyton-Jones wrote: | What is not so nice is that you take a new keyword ('for'), which is | quite likely to have been used as a variable name in existing code. (Or | does it work out to use one of the 'special' names here?) The latter is what Bjorn has done. That is, 'for' is only special in this one context. You can use it freely otherwise. As I understand it anyway. Yes. There is even a for function somewhere in the libraries (or was it the testsuite, can't remeber), which tripped up one of my early versions, before I had remembered to make for as a special ID in the parser. | I think it would be useful to write the proposal in complete detail up | on the Haskell' wiki. Yes please. Bjorn? (It may just be a qn of transcribing the user manual stuff you have written.) Sure. It seems that I have to be on the committee to write to the Wiki. Can I join it? /Björn ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
Re: Proposal for stand-alone deriving declarations?
Off-list, Greg Fitzgerald pointed out that: Those wanting to use the SYB library may want to write something like this for every datatype in their heirarchy: deriving Data, Typable for Person, Team, Department, Company That seems like a useful extension to me, and the meaning is obvious. This would as far as I can tell not be possible (or at least not readable) without the for. /Björn On 5 okt 2006, at 20.58, Bjorn Bringert wrote: We considered that syntax, but decided against it. Stand-alone deriving declarations are made to be as similar as possible to the current deriving mechanism, rather than be similar to instance declarations. The basic reason for maintaining a syntactic distinction between instance declarations and deriving declarations is to make the programmer aware of the restrictions of the deriving mechanism. These are some things that make deriving declarations different from instance declarations: - You can only derive instances for data types and newtypes. - For deriving declarations, the compiler figures out the constraints, whereas the programmer writes them for instance declarations. - In GHC, you can declare non-Haskell98 instances such as Eq (C X) where X is a concrete type, but you can't do deriving for them. - When deriving instances of multi-parameter type classes (again non-standard), the newtype for which the deriving is made must be the last argument to the class. If the syntax were deriving (Class T1 ... Tn), it might not be clear to the reader what type the deriving is for. I can't see any technical reason not to do as you propose. One advantage would be that it makes it possible to fully subsume GHC's current deriving extensions (though there are other ways to do this, see my recent e-mail to ghc-cvs). One slight disadvantage is that it does require a bit more footwork in the compiler to figure out which type to do the deriving for. /Björn On 5 okt 2006, at 19.58, Iavor Diatchki wrote: Hello, A question about the syntax: would there be a problem if we made the 'deriving' declaration look like an instance? Then we would not need the special identifier 'for', and also we have a more standard looking notation. I am thinking something like: deriving Show SomeType deriving Eq (AnotherType a) -Iavor On 10/5/06, Björn Bringert [EMAIL PROTECTED] wrote: Simon Peyton-Jones wrote: | What is not so nice is that you take a new keyword ('for'), which is | quite likely to have been used as a variable name in existing code. (Or | does it work out to use one of the 'special' names here?) The latter is what Bjorn has done. That is, 'for' is only special in this one context. You can use it freely otherwise. As I understand it anyway. Yes. There is even a for function somewhere in the libraries (or was it the testsuite, can't remeber), which tripped up one of my early versions, before I had remembered to make for as a special ID in the parser. | I think it would be useful to write the proposal in complete detail up | on the Haskell' wiki. Yes please. Bjorn? (It may just be a qn of transcribing the user manual stuff you have written.) Sure. It seems that I have to be on the committee to write to the Wiki. Can I join it? /Björn ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime