Subject: Re: publish
From: Craig Chambers (chambers@cs.washington.edu)
Date: Fri Mar 30 2001 - 11:03:11 PST
Polymorphic synonyms! ML, look out!
Oh bah doh bee -- backquotes in synonyms?! Purely syntactic substitutions?!
Ow, my head hurts. But probably very cool, once I get my head around it.
-- Craig
P.S. If I had to suggest the next thing to work on, it would be to remove the
restrictions on synonyms not being able to refer to other synonyms in their
definition, and similarly for object or type declarations not to be able to
refer to synonyms (I think that was the rule). Type synonyms should be usable
wherever other types are allowed, as long as there are no cyclic chains of
definitions (by some definition). I admit it seems pretty tricky to get the
rules right, probably equivalent to your current work on well-foundedness of
constrained subtype declarations. Maybe there's a simpler rule that would be
sufficient, e.g. no syntactically recursive definitions of type synonyms.
Vassily Litvinov wrote:
>
> I have published in Cecil/src/compiler. Essentially these are changes
> to typechecker and parser, to
> - allow polymorphic synonyms, and
> - change the syntax of synonym decls (= instead of standsfor)
>
> Baseline binaries to be installed shortly.
> I tested synonyms, but watch out for bugs.
>
> DETAILS
>
> Synonyms are allowed to be parameterized and/or have type context
> just like other polymorphic declarations:
>
> forall F where W1: type synonym somename[T1,T2] = sometype where W2;
>
> where [T1,T2] are synonym's formal parameters (optional).
>
> NOTE I replaced the "standsfor" keyword (which is no longer a Cecil keyword)
> with the "=" operator symbol.
>
> DESUGARING RULES:
> When such synonym is used (e.g. as in somename[int,string]),
> - the "sometype" gets syntactically replaced by substituting
> the actual type parameters (here int, string) for the formals
> (here T1, T2)
> - the synonym's other type variables (aka "implicit" type parameters) are
> replaced by fresh type variables added to the enclosing declaration's
> "forall" clause
> - the synonym's constraints are added (after the above substitutions)
> to the enclosing declaration's "where" clause.
>
> In method bodies, (global) variable declarations or field initializers
> reference to synonyms with constraints and/or implicit type variables
> is disallowed.
>
> For example, given the following
>
> forall Key, Value where Value <= num:
> type synonym table[Value] = table[Key,Value];
>
> method foo(x:table[`T]):void { ... }
>
> The header of method foo will be desugared into:
>
> forall T, Key' where `T <= num: method foo(x:table[Key,T]):void { ... }
>
> Referring to table[T] or table[int] inside the elipses generates type error.
>
> BACKQUOTE SUGAR is supported by treating the substitutions as purely
> syntactic. For example, given
>
> type bounded[T1, T2, T3] where signature bound(T1,T2,T3):void;
> type synonym bsyn[Q] = bounded[Q, int, `R];
>
> (where `R is the synonym's implicit type parameter), bsyn desugars as:
>
> bsyn[T] -> bounded[T, int, `R]
> bsyn[`T] -> bounded[`T, int, `R]
> bsyn[string] -> bounded[string, int, `R]
>
> BACKQUOTE SUGAR ON NAMED TYPES
> While I am on this, I'll explain this one. Assume named type declaration:
>
> forall T1, T2, T3 where W: type mytype[T1,T2];
>
> When an instance of "mytype" occurs inside the header of a polymorphic
> declaration and (at least) one of the actuals of "mytype" is a type
> variable with backquote (as in mytype[int,`Q]), that header is
> extended with fresh variables corresponding to mytype's implicit
> parameters (T3 in this case) and those constraints from W that
> reference mytype's formals whose actuals have backquotes (after
> appropriate substitutions).
>
> For example, if the header references mytype[`Q1,Q2], then the
> declaration is extended with T3' and those constraints from W that
> reference T1 or T3, upon substitution T1<-Q1, T2<-Q2, T3<-T3'.
>
> Outside of polymorphic declaration headers, backquotes are not allowed
> and therefore declarations are not extended.
>
> -Vass
>
> _______________________________________________
> Cecil mailing list
> Cecil@cs.washington.edu
> http://majordomo.cs.washington.edu/mailman/listinfo/cecil
_______________________________________________
Cecil mailing list
Cecil@cs.washington.edu
http://majordomo.cs.washington.edu/mailman/listinfo/cecil
This archive was generated by hypermail 2b25 : Fri Mar 30 2001 - 11:04:06 PST