hydromatic / morel

Standard ML interpreter, with relational extensions, implemented in Java
Apache License 2.0
291 stars 15 forks source link

Type annotations in patterns #138

Closed julianhyde closed 2 years ago

julianhyde commented 2 years ago

Allow type annotations in patterns. Examples:

val x: int = 1;
val p: int * bool = (2, true);
val f (x: int) = x + 1;
val g (e: {name: string, deptno: int}) = e.name;

Also in expressions:

1: int;
(2, true): int * bool;
[]: int list;
(1: int) + (2: int);
String.size ("abc": string): int;

And also in function declarations:

fun hello (name: string, code: int): string =
    "hello!";
fun firstOrSecond (e1 :: e2 :: rest): int = e2
  | firstOrSecond (e1 :: rest) = e1;