From d0614dd946baf05375172d7a50f5eb250b9a7b00 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 10 Dec 2022 23:59:14 +0200 Subject: Update spec.md --- spec.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec.md b/spec.md index 505524d..1b25e6b 100644 --- a/spec.md +++ b/spec.md @@ -5,7 +5,7 @@ - Boolean functions marked with ? (convention) - Loops implemented with recursion -## Value types +## Values and types Integer 3 Float -3.14 @@ -17,6 +17,12 @@ Hash map { a 1 b 2 } Function (\[x y] (+ x y)) +Functions generally only accept monomorphic values, but some builtins are polymorphic, either expecting any arbitrary type (as is the case in e.g. `match` and `fmt`), or only a range of types (type classes). User defined functions can be made "polymorphic" by matching on the return value of `(type arg)`, where `arg` is the argument of the user defined function. + +There are 2 language defined "type classes": `Num` and `Seq`. Integers and floats are instances of `Num`, while Strings and Vectors are instances of `Seq`. Type classes are not a thing per se in the interpreter, but they are a useful concept to "formalize" some builtin functions and their inputs. `Num` values can be e.g. added together with `+`. `Seq` values can be used to call functions like `head` and `tail` and `len`. + +Collections (vectors, hash maps) are heterogenous, which means that a single collection can contains values of multiple types. + ## Syntax ### Function calls -- cgit v1.3