Update spec.md

This commit is contained in:
2025-09-15 16:23:11 +02:00
parent 74075b4612
commit c5d85ad7e9

50
spec.md
View File

@@ -345,8 +345,7 @@ The only operator with type overloading
TODO TODO
# coding patterns (for users only) # (for users) programming patterns
## labelled arguments ## labelled arguments
``` ```
def List.remove_prefix(prefix: t List, list: 'from t List) 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]) 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 # OLD SPECIFICATION STARTING HERE
## automatic return types ## 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 ## pattern matching
``` ```
type Option[t] = 'None | 'Some t type Option[t] = 'None | 'Some t