From f9a2babf958d420f70c1bfb4b5e1c68add2ff1eb Mon Sep 17 00:00:00 2001 From: Alexander Nutz Date: Fri, 12 Sep 2025 11:23:11 +0200 Subject: [PATCH] v0.0.9: change how functions work --- spec.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/spec.md b/spec.md index 3a883a3..f6cc87a 100644 --- a/spec.md +++ b/spec.md @@ -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]` ```