From c5d85ad7e9e752739c39b3c2cb530bc29928cadc Mon Sep 17 00:00:00 2001 From: Alexander Nutz Date: Mon, 15 Sep 2025 16:23:11 +0200 Subject: [PATCH] Update spec.md --- spec.md | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/spec.md b/spec.md index a09a699..a7c566a 100644 --- a/spec.md +++ b/spec.md @@ -345,8 +345,7 @@ The only operator with type overloading TODO -# coding patterns (for users only) - +# (for users) programming patterns ## labelled arguments ``` def List.remove_prefix(prefix: t List, list: 'from t List) @@ -357,6 +356,39 @@ List.remove_prefix([1,2], 'from [1,2,3,4]) List.remove_prefix([1,2], [1,2,3,4]) ``` +## promising a list of at least one element +Returning a `'Cons {v: Int, next: Int List}` +indicates that the list contains at least one element. +And this is even assignable to `Int List` + + +# (for implementors) recommendations +## Don't do deep-copies of type objects +types could have hundreds of enum cases + + +## Store original type alias names in types, as hints +To give more information to the user in error messages + +Which of these is more readable and user friendly... +- `&a {v: 'None | 'Some {high:Int16,low:Int16}, next: a}` +- `Int32 Option List` + + +## Perform fuzzy match to give suggestions for correcting errors +Non-nominal record types have the issue of typos propagating really far trough the code, +making them hard to debug. + +Give fuzzy-matched suggestions for at the following things: +- function names +- local names +- non-nominal record fields +- union tags + + +## Store as much debug in fromation as possible until type checking is done + + # OLD SPECIFICATION STARTING HERE ## automatic return types @@ -366,20 +398,6 @@ def add(a: Num, b: Num) -> _ { } ``` -## templated generics -``` -# Type of add is: template a, b: a -> b -> _ -def [a,b] add(a: a, b: b) -> _ { - a + b -} - -add(1,2) - -add(1)(2) # error: partial function application of templated functions not allowed - -add(1,"2") # error: in template expansion of add[Num,List[Char]]: No definition for `Num + List[Char]` -``` - ## pattern matching ``` type Option[t] = 'None | 'Some t