From ecc037415b7998f29f66d487ee2bc6d5df1be3fe Mon Sep 17 00:00:00 2001 From: Alexander Nutz Date: Mon, 15 Sep 2025 21:42:29 +0200 Subject: [PATCH] Update spec.md --- spec.md | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/spec.md b/spec.md index a7c566a..7c611fe 100644 --- a/spec.md +++ b/spec.md @@ -21,6 +21,29 @@ One of: - `'Case1 t1 | 'Case2 t2 | ...?Identifier`: partial tagged union type, `Identifier` - `{field1: xt, field2: yt, ...?Identifier}`: partial non-nominal record type, `Identifier` + +## Generic types +Means that the structure of that value is not available at compile time. +This implies that you can dispatch on those values. +This means that you can not write a magic `List.toString` function, because you would have to dispatch on `toString`, +so you have to do something like this: +``` +def List.toString = + toStr: (t -> Char List) -> + list: t List -> + ... +``` +This is also the case for equality, and `List.contains`: +``` +def List.any = + fn: (t -> Bool) -> + list: t List -> + ... + +List.any(x -> x = y, list) +``` + + ## Recursive types Recursive / self-referential types @@ -68,9 +91,6 @@ type Uint8 = {...?Uint8} -## Syntax -TODO ebnf - ## Compatible-with Check if type is compatible-with / assignable-to type requirements. @@ -390,6 +410,19 @@ Give fuzzy-matched suggestions for at the following things: +# Syntax +Note that the order of syntax cases matter! +``` +Identifier = { (* ( a-z | A-Z | 0-9 | _ | - | . | # ) TODO: cvt to ebnf *) }; +Partial Type = '?', Identifier; +Union Type Case = '\'', Identifier, [ Type (*default to Unit*) ]; +Union Type = Union Type Case, { '|', Union Type Case}; +Record Type Field = Identifier, ':', Type; +Record Type = '{', [Record Type Field, {',' Record Type Field }], [ '...', Partial Type ], '}'; +Type = Partial Type | Identifier | Union Type | Record Type | TODO; +``` + + # OLD SPECIFICATION STARTING HERE ## automatic return types ```