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 &lt;<a href=3D"mailto:[email protected]">=
[email protected]</a>&gt;:<br>
<div><div></div><div class=3D"h5">&gt; I&#39;ve been away. =A0I hope others=
 will reply to this thread too; whatever you<br>
&gt; decide will end up in TH indefinitely. =A0I know that Roman is interes=
ted in<br>
&gt; this.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; =B7 =A0 =A0 =A0 =A0 You focus just on type families in class declarati=
ons (which is<br>
&gt; indeed where associated types started). =A0But I suggest you also allo=
w them<br>
&gt; at top level, as GHC does using the syntax<br>
&gt;<br>
&gt; type family T a :: *<br>
&gt;<br>
&gt; Indeed, since you propose to add to Dec, that&#39;ll happen automatica=
lly. =A0But<br>
&gt; perhaps &quot;AssocTySynKindD&quot; is not a good name. Perhaps &quot;=
TySynFamilyD&quot;?<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; =B7 =A0 =A0 =A0 =A0 GHC uses<br>
&gt;<br>
&gt; type instance T [a] =3D Tree a<br>
&gt;<br>
&gt; as the way to add an equation to the definition of T. =A0So perhaps<br=
>
&gt; &quot;TySynInstance&quot; rather than &quot;AssocTySynD&quot;?<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; =B7 =A0 =A0 =A0 =A0 I agree that it&#39;d be good to do data type/newt=
ype families at the<br>
&gt; same time. =A0Roman needs this.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; =B7 =A0 =A0 =A0 =A0 Your proposal for kinds looks fine.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Simon<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; From: <a href=3D"mailto:[email protected]">haskell-cafe=
[email protected]</a><br>
&gt; [mailto:<a href=3D"mailto:[email protected]">haskell-ca=
[email protected]</a>] On Behalf Of Jos=E9 Pedro Magalh=E3es<br>
&gt; Sent: 11 November 2008 11:11<br>
&gt; To: Haskell Cafe<br>
&gt; Subject: Re: [Haskell-cafe] Proposal for associated type synonyms in<b=
r>
&gt; Template Haskell<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Hello Thomas,<br>
&gt;<br>
&gt; I see this is a proposal for a partial implementation of #1673<br>
&gt; (<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>
&gt; the remaining syntax (associated datatypes and type families) would al=
so be<br>
&gt; defined and implemented in TH. Or maybe there isn&#39;t much demand fo=
r this?...<br>
&gt;<br>
&gt;<br>
&gt; Cheers,<br>
&gt; Pedro<br>
&gt;<br>
&gt; On Wed, Nov 5, 2008 at 15:57, Thomas van Noort &lt;<a href=3D"mailto:t=
[email protected]">[email protected]</a>&gt; wrote:<br>
&gt;<br>
&gt; Hello,<br>
&gt;<br>
&gt; Recently, we released a library on Hackage for generic rewriting (pack=
age<br>
&gt; &quot;rewriting&quot; if you are curious). The user of the library is =
expected to<br>
&gt; define type class instances to enable rewriting on his or her own data=
types.<br>
&gt; As these instances follow the datatype declarations closely, we tried =
to<br>
&gt; generate the instances using Template Haskell. Unfortunately, associat=
ed<br>
&gt; type synonyms are not yet supported by TH.<br>
&gt;<br>
&gt; After a presentation at the WGP&#39;08, Simon encouraged us to write a=
 proposal<br>
&gt; about adding associated type synonyms to TH, so that it can be added t=
o GHC.<br>
&gt; So, here is our proposal.<br>
&gt;<br>
&gt; The TH AST must allow 1) kind declarations of associated type synonyms=
<br>
&gt; in class declarations and 2) their definitions in instance declaration=
s. For<br>
&gt; example,<br>
&gt;<br>
&gt; class Foo a where<br>
&gt; =A0type Bar a :: *<br>
&gt;<br>
&gt; instance Foo Int where<br>
&gt; =A0type Bar Int =3D String<br>
&gt;<br>
&gt; The TH library defines a datatype Dec which contains a constructor for=
 class<br>
&gt; declarations and instance declarations:<br>
&gt;<br>
&gt; data Dec<br>
&gt; =3D ...<br>
&gt; | ClassD Cxt Name [Name] [FunDep] [Dec]<br>
&gt; | InstanceD Cxt Type [Dec]<br>
&gt; =A0...<br>
&gt;<br>
&gt; 1) Associated type synonym kind declarations<br>
&gt;<br>
&gt; We suggest to add a constructor to the Dec type:<br>
&gt;<br>
&gt; =A0...<br>
&gt; | AssocTySynKindD Name [Name] (Maybe Kind)<br>
&gt; =A0...<br>
&gt;<br>
&gt; assocTySynKindD :: Name -&gt; [Name] -&gt; Maybe KindQ -&gt; DecQ<br>
&gt;<br>
&gt; The first field is the name of the associated type synonym, the second=
 field<br>
&gt; is a list of type variables, and the third field is an optional kind. =
Since<br>
&gt; kinds are not yet defined in TH, we have to add some kind of kind defi=
nition<br>
&gt; (pun intended):<br>
&gt;<br>
&gt; data Kind<br>
&gt; =3D StarK<br>
&gt; | ArrowK Kind Kind<br>
&gt;<br>
&gt; type KindQ =3D Q Kind<br>
&gt; starK :: KindQ<br>
&gt; arrowK :: KindQ -&gt; KindQ -&gt; KindQ<br>
&gt;<br>
&gt; We explicitly choose not to reuse the Type type to define kinds (i.e.,=
 type<br>
&gt; Kind =3D Type as in GHC) since we think a separation between the two w=
orlds is<br>
&gt; much clearer to the users of TH.<br>
&gt;<br>
&gt; 2) Associated type synonym definitions<br>
&gt;<br>
&gt; We suggest to add another constructor to the Dec type:<br>
&gt;<br>
&gt; =A0...<br>
&gt; | AssocTySynD Name [Type] Type<br>
&gt; =A0...<br>
&gt;<br>
&gt; assocTySynD :: Name -&gt; [TypeQ] -&gt; TypeQ -&gt; DecQ<br>
&gt;<br>
&gt; The first field is the name of the type synonym, the second field is a=
 list<br>
&gt; of type arguments, and the third field is the body of the type synonym=
.<br>
&gt;<br>
&gt; We would like to hear your comments to this proposal.<br>
&gt;<br>
&gt; Regards,<br>
&gt; 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==--