From 993e64759d168522ec70b7c5398182483383d568 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Fri, 22 Aug 2025 00:51:09 +0300 Subject: doc: added documentation on writing types --- TUTORIAL.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/TUTORIAL.md b/TUTORIAL.md index 9c85478..4ae36db 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -130,6 +130,43 @@ and after it it is too, while in the middle term where `x = 2` is defined, `x = 2`. +Types +----- + +Types are written as seen in the return types in the REPL. +The base types of myslip are +* `Int` for integer +* `Bool` for boolean +* `Nil` for `()` +* `Type` for type literals +* `Let` (what'd be the sensible type if not a special one?) +* `Quote`, `Vector` and `Sum` for use in data structures. +The types used in data structures will be covered later. + +These can be combined using the arrow type, list type and +vector type. + +`(A -> B)` denotes a function with arguments of type `A` +and a return value of type `B`. + +`(A B C D)` denotes a 4-length list with the respective types +at respective positions. Though if it is an actual list not +to be interpreted, in most cases a `Quote` will be present in +the type: `(Quote (A B C D))`. Note that the length of a list +can be any nonnegative integer (within memory constraints), +but it needs to be fixed. + +`(A ...)` denotes a list the length of which is not known and +whose each element is of type `A`. If this is in a vector +structure, `Vector` is prepended as such: `(Vector (A ...))`. + +`(Sum A B)` denotes the type of a coproduct, the left type of +which is `A` and right type `B`. + +Generics have limited support in myslip. +They are written in uppercase. + + Functions --------- -- cgit v1.2.3