Skip to content

Draft: PoC: use tuple constructors

E. Rivas requested to merge er433/typer/tuple-constructor into dev

Motivation and Context

We introduce variant types with a union-like syntax in JsLIGO:

type t = | ["Foo", int, string] | ["Bar"] | ["C", option<int>];

However, constructor application is used using a different syntax: Foo(42, "hello")

This is a proof of concept MR trying a more regular syntax for constructor application by modifying mostly the typer.

Description

In this MR we try some small local changes on the typer to allow writing constructor application as ["Foo", 42, "hello"].

After those changes, we can currently type:

type t = | ["Foo", int, string] | ["Bar"] | ["C", option<int>];

const tx : t = ["Foo", 42, "bar"];
const y = ["Bar"]; // t
const l = ["x", "y"]; // [string, string]
const i : [string, option<int>] = ["C", ["Some", 42]];

const j = (y) => match (y) {
  when(["Foo", i, _s]): i + 1;
  when(["Bar"]): -1;
  when(["C", ["Some", n]]): n;
  when(["C", ["None"]]): -2;
}; // (y : t) => int
const h = ["Some", ["C", ["None"]]]; // t

Component

  • compiler
  • website
  • webide
  • vscode-plugin
  • debugger

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (non-breaking change that improves performance)
  • None (change with no changelog)

Changelog

Checklist:

  • If a new syntax has been introduced, put a message on slack ligo-lsp
  • Changes follow the existing coding style (use dune @fmt to check).
  • Tests for the changes have been added (for bug fixes / feature).
  • Documentation has been updated.
  • Changelog description has been added (if appropriate).
  • Start titles under ## Changelog section with #### (if appropriate).
  • There is no image or uploaded file in changelog
  • Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by E. Rivas

Merge request reports