v0.0.9: change how functions work

This commit is contained in:
2025-09-12 11:23:11 +02:00
parent 1f25d9256c
commit f9a2babf95

27
spec.md
View File

@@ -10,6 +10,8 @@ Most important ones:
- `List[T]`: (linked-) list of `T`
- `Char`: unicode codepoint
- `Unit`: nothing
- `i -> o`: function
- `template a, b: t`
Advanced (uncommon) types:
- `Int8`, `Int16`, ...
@@ -18,23 +20,43 @@ Advanced (uncommon) types:
## Functions
```
# the type of msg is: List[Char] -> List[Char]
def msg(username: List[Char]) : List[Char] {
"Hello, " ++ username ++ "!" # last expr is returned
}
# the type of main is: Unit -> Unit
def main() {
print("hi")
}
main()
```
## Anonymus functions
```
The type of List.map is List[t] -> (t -> t) -> List[t]
List.map(li, x:Num -> x * 2)
```
## Simple, forward type-inference
```
def zero () : Flt32 {
3.1 # error: got Num, but expected F32
3.1 # error: got Num, but expected Flt32
}
```
## Partial function applications
```
# type of add is Num -> Num -> Num
def add(a: Num, b: Num) : Num {
a + b
}
let a = add(1) # type of a is Num -> Num
let b = a(2) # type of b is Num
# b is 3
```
## Bindings
```
let name = "Max"
@@ -134,12 +156,15 @@ 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]`
```