Update spec.md
This commit is contained in:
50
spec.md
50
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
|
||||
|
Reference in New Issue
Block a user