Skip to content

Commit

Permalink
Add sugar for declaration punning
Browse files Browse the repository at this point in the history
This is analogous to record (or definition or binding) punning where one
can write e.g.

    x = 1;
    y = 2;
    xy = {x; y};  ;; same as {x = x; y = y}

Now that notation also exists for declarations.

This is motivated by the upcoming intersection like signature combination
operator `&`.  Consider a `MAP` signature:

    type MAP = {
      type t _;
      Key: ORD;
      ;; ...
    };

With the declaration punning notation and intersection like combination, one
could write

    Map (Key: ORD) :> MAP & {Key} = ;; ...

to refine the `MAP` signature.
  • Loading branch information
polytypic committed Feb 22, 2020
1 parent e16f231 commit 3db14c2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ D ::= ...
X A1 ... An = E ~> X : A1 -> ... -> An -> (= E)
type X A1 ... An ~> X : A1 => ... => An => type
type X A1 ... An = T ~> X : A1 => ... => An => (= type T)
X ~> X : (= X)
(expressions)
E ::= ...
Expand Down
2 changes: 2 additions & 0 deletions parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ atdec :
| head typparamlist EQUAL exp
{ VarD($1, funT($2, EqT($4)@@ati 4, Pure@@ati 3)@@span[ati 2; ati 4])
@@at() }
| name
{ VarD($1, funT([], EqT(VarE($1)@@ati 1)@@ati 1, Pure@@ati 1)@@ati 1)@@at() }
| TYPE head typparamlist EQUAL typ
{ VarD($2, funT($3, EqT(TypE($5)@@ati 5)@@ati 5, Pure@@ati 4)@@at())
@@at() }
Expand Down
4 changes: 4 additions & 0 deletions regression.1ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ record_inference x = x.works_a_little;

;;

type DEC_PUNNING = {int; list};

;;

Equivalence: {
type t a b;

Expand Down

0 comments on commit 3db14c2

Please sign in to comment.