Re: Proposal for associated type synonyms in Template Haskell
Sean Leather <[email protected]> Thu, 19 Mar 2009 16:43:03 +0100
| Newsgroups | gmane.comp.lang.haskell.cafe,gmane.comp.lang.haskell.template |
|---|---|
| Message-ID | <[email protected]> |
--===============1320810044== Content-Type: multipart/alternative; boundary=001636c5a3cbdedc6504657aa77d --001636c5a3cbdedc6504657aa77d Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable It looks like Manuel Chakravarty is making some progress on this. http://hackage.haskell.org/trac/ghc/ticket/1673#comment:11 Sean On Thu, Jan 15, 2009 at 21:57, Nicolas Frisby wrote: > Any movement on this? > > (I am actually just looking forward to generating kind ascriptions and > having access to the kinds when processing TH.Dec, TH.Type, and such.) > > 2008/11/27 Simon Peyton-Jones <[email protected]>: > > I've been away. I hope others will reply to this thread too; whatever > you > > decide will end up in TH indefinitely. I know that Roman is interested > in > > this. > > > > > > > > =B7 You focus just on type families in class declarations (whic= h is > > indeed where associated types started). But I suggest you also allow > them > > at top level, as GHC does using the syntax > > > > type family T a :: * > > > > Indeed, since you propose to add to Dec, that'll happen automatically. > But > > perhaps "AssocTySynKindD" is not a good name. Perhaps "TySynFamilyD"? > > > > > > > > =B7 GHC uses > > > > type instance T [a] =3D Tree a > > > > as the way to add an equation to the definition of T. So perhaps > > "TySynInstance" rather than "AssocTySynD"? > > > > > > > > =B7 I agree that it'd be good to do data type/newtype families = at > the > > same time. Roman needs this. > > > > > > > > =B7 Your proposal for kinds looks fine. > > > > > > > > Simon > > > > > > > > From: [email protected] > > [mailto:[email protected]] On Behalf Of Jos=E9 Pedro > Magalh=E3es > > Sent: 11 November 2008 11:11 > > To: Haskell Cafe > > Subject: Re: [Haskell-cafe] Proposal for associated type synonyms in > > Template Haskell > > > > > > > > Hello Thomas, > > > > I see this is a proposal for a partial implementation of #1673 > > (http://hackage.haskell.org/trac/ghc/ticket/1673). Maybe it would be > good if > > the remaining syntax (associated datatypes and type families) would als= o > be > > defined and implemented in TH. Or maybe there isn't much demand for > this?... > > > > > > Cheers, > > Pedro > > > > On Wed, Nov 5, 2008 at 15:57, Thomas van Noort <[email protected]> wrote: > > > > Hello, > > > > Recently, we released a library on Hackage for generic rewriting (packa= ge > > "rewriting" if you are curious). The user of the library is expected to > > define type class instances to enable rewriting on his or her own > datatypes. > > As these instances follow the datatype declarations closely, we tried t= o > > generate the instances using Template Haskell. Unfortunately, associate= d > > type synonyms are not yet supported by TH. > > > > After a presentation at the WGP'08, Simon encouraged us to write a > proposal > > about adding associated type synonyms to TH, so that it can be added to > GHC. > > So, here is our proposal. > > > > The TH AST must allow 1) kind declarations of associated type synonyms > > in class declarations and 2) their definitions in instance declarations= . > For > > example, > > > > class Foo a where > > type Bar a :: * > > > > instance Foo Int where > > type Bar Int =3D String > > > > The TH library defines a datatype Dec which contains a constructor for > class > > declarations and instance declarations: > > > > data Dec > > =3D ... > > | ClassD Cxt Name [Name] [FunDep] [Dec] > > | InstanceD Cxt Type [Dec] > > ... > > > > 1) Associated type synonym kind declarations > > > > We suggest to add a constructor to the Dec type: > > > > ... > > | AssocTySynKindD Name [Name] (Maybe Kind) > > ... > > > > assocTySynKindD :: Name -> [Name] -> Maybe KindQ -> DecQ > > > > The first field is the name of the associated type synonym, the second > field > > is a list of type variables, and the third field is an optional kind. > Since > > kinds are not yet defined in TH, we have to add some kind of kind > definition > > (pun intended): > > > > data Kind > > =3D StarK > > | ArrowK Kind Kind > > > > type KindQ =3D Q Kind > > starK :: KindQ > > arrowK :: KindQ -> KindQ -> KindQ > > > > We explicitly choose not to reuse the Type type to define kinds (i.e., > type > > Kind =3D Type as in GHC) since we think a separation between the two wo= rlds > is > > much clearer to the users of TH. > > > > 2) Associated type synonym definitions > > > > We suggest to add another constructor to the Dec type: > > > > ... > > | AssocTySynD Name [Type] Type > > ... > > > > assocTySynD :: Name -> [TypeQ] -> TypeQ -> DecQ > > > > The first field is the name of the type synonym, the second field is a > list > > of type arguments, and the third field is the body of the type synonym. > > > > We would like to hear your comments to this proposal. > > > > Regards, > > Thomas > --001636c5a3cbdedc6504657aa77d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable It looks like Manuel Chakravarty is making some progress on this.<br><br><a= href=3D"http://hackage.haskell.org/trac/ghc/ticket/1673#comment:11">http:/= /hackage.haskell.org/trac/ghc/ticket/1673#comment:11</a><br><br>Sean<br><br= > <div class=3D"gmail_quote">On Thu, Jan 15, 2009 at 21:57, Nicolas Frisby wr= ote:<br><blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid r= gb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Any movem= ent on this?<br> <br> (I am actually just looking forward to generating kind ascriptions and<br> having access to the kinds when processing TH.Dec, TH.Type, and such.)<br> <br> 2008/11/27 Simon Peyton-Jones <<a href=3D"mailto:[email protected]">= [email protected]</a>>:<br> <div><div></div><div class=3D"h5">> I've been away. =A0I hope others= will reply to this thread too; whatever you<br> > decide will end up in TH indefinitely. =A0I know that Roman is interes= ted in<br> > this.<br> ><br> ><br> ><br> > =B7 =A0 =A0 =A0 =A0 You focus just on type families in class declarati= ons (which is<br> > indeed where associated types started). =A0But I suggest you also allo= w them<br> > at top level, as GHC does using the syntax<br> ><br> > type family T a :: *<br> ><br> > Indeed, since you propose to add to Dec, that'll happen automatica= lly. =A0But<br> > perhaps "AssocTySynKindD" is not a good name. Perhaps "= TySynFamilyD"?<br> ><br> ><br> ><br> > =B7 =A0 =A0 =A0 =A0 GHC uses<br> ><br> > type instance T [a] =3D Tree a<br> ><br> > as the way to add an equation to the definition of T. =A0So perhaps<br= > > "TySynInstance" rather than "AssocTySynD"?<br> ><br> ><br> ><br> > =B7 =A0 =A0 =A0 =A0 I agree that it'd be good to do data type/newt= ype families at the<br> > same time. =A0Roman needs this.<br> ><br> ><br> ><br> > =B7 =A0 =A0 =A0 =A0 Your proposal for kinds looks fine.<br> ><br> ><br> ><br> > Simon<br> ><br> ><br> ><br> > From: <a href=3D"mailto:[email protected]">haskell-cafe= [email protected]</a><br> > [mailto:<a href=3D"mailto:[email protected]">haskell-ca= [email protected]</a>] On Behalf Of Jos=E9 Pedro Magalh=E3es<br> > Sent: 11 November 2008 11:11<br> > To: Haskell Cafe<br> > Subject: Re: [Haskell-cafe] Proposal for associated type synonyms in<b= r> > Template Haskell<br> ><br> ><br> ><br> > Hello Thomas,<br> ><br> > I see this is a proposal for a partial implementation of #1673<br> > (<a href=3D"http://hackage.haskell.org/trac/ghc/ticket/1673" target=3D= "_blank">http://hackage.haskell.org/trac/ghc/ticket/1673</a>). Maybe it wou= ld be good if<br> > the remaining syntax (associated datatypes and type families) would al= so be<br> > defined and implemented in TH. Or maybe there isn't much demand fo= r this?...<br> ><br> ><br> > Cheers,<br> > Pedro<br> ><br> > On Wed, Nov 5, 2008 at 15:57, Thomas van Noort <<a href=3D"mailto:t= [email protected]">[email protected]</a>> wrote:<br> ><br> > Hello,<br> ><br> > Recently, we released a library on Hackage for generic rewriting (pack= age<br> > "rewriting" if you are curious). The user of the library is = expected to<br> > define type class instances to enable rewriting on his or her own data= types.<br> > As these instances follow the datatype declarations closely, we tried = to<br> > generate the instances using Template Haskell. Unfortunately, associat= ed<br> > type synonyms are not yet supported by TH.<br> ><br> > After a presentation at the WGP'08, Simon encouraged us to write a= proposal<br> > about adding associated type synonyms to TH, so that it can be added t= o GHC.<br> > So, here is our proposal.<br> ><br> > The TH AST must allow 1) kind declarations of associated type synonyms= <br> > in class declarations and 2) their definitions in instance declaration= s. For<br> > example,<br> ><br> > class Foo a where<br> > =A0type Bar a :: *<br> ><br> > instance Foo Int where<br> > =A0type Bar Int =3D String<br> ><br> > The TH library defines a datatype Dec which contains a constructor for= class<br> > declarations and instance declarations:<br> ><br> > data Dec<br> > =3D ...<br> > | ClassD Cxt Name [Name] [FunDep] [Dec]<br> > | InstanceD Cxt Type [Dec]<br> > =A0...<br> ><br> > 1) Associated type synonym kind declarations<br> ><br> > We suggest to add a constructor to the Dec type:<br> ><br> > =A0...<br> > | AssocTySynKindD Name [Name] (Maybe Kind)<br> > =A0...<br> ><br> > assocTySynKindD :: Name -> [Name] -> Maybe KindQ -> DecQ<br> ><br> > The first field is the name of the associated type synonym, the second= field<br> > is a list of type variables, and the third field is an optional kind. = Since<br> > kinds are not yet defined in TH, we have to add some kind of kind defi= nition<br> > (pun intended):<br> ><br> > data Kind<br> > =3D StarK<br> > | ArrowK Kind Kind<br> ><br> > type KindQ =3D Q Kind<br> > starK :: KindQ<br> > arrowK :: KindQ -> KindQ -> KindQ<br> ><br> > We explicitly choose not to reuse the Type type to define kinds (i.e.,= type<br> > Kind =3D Type as in GHC) since we think a separation between the two w= orlds is<br> > much clearer to the users of TH.<br> ><br> > 2) Associated type synonym definitions<br> ><br> > We suggest to add another constructor to the Dec type:<br> ><br> > =A0...<br> > | AssocTySynD Name [Type] Type<br> > =A0...<br> ><br> > assocTySynD :: Name -> [TypeQ] -> TypeQ -> DecQ<br> ><br> > The first field is the name of the type synonym, the second field is a= list<br> > of type arguments, and the third field is the body of the type synonym= .<br> ><br> > We would like to hear your comments to this proposal.<br> ><br> > Regards,<br> > Thomas</div></div></blockquote></div><br> --001636c5a3cbdedc6504657aa77d-- --===============1320810044== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe --===============1320810044==--