From 3309cad8c27471f6e3c48a6ecea836ee3f9a3d7e Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sat, 16 Aug 2025 03:43:23 +0300 Subject: doc: added <> and factorial example to TUTORIAL.md --- TUTORIAL.md | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/TUTORIAL.md b/TUTORIAL.md index c8eaab2..2f4edf8 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -211,6 +211,12 @@ An empty vector is created by passing its type to nil: vector : (Int ...) ``` +Two vectors can be concatenated using the `<>`-operator: +```console +> (<> (vector 1 2) (vector 3 4)) +(vector 1 2 3 4) : (Vector (Int ...)) +``` + The standard library provides the function `sum` to calculate the sum of a vector of integers. Through type conversions, this works for lists too. @@ -280,17 +286,24 @@ General recursion ----------------- General recursion in myslip is achieved through the -fixed point operator `fix`. - -TODO - - -Understanding error messages ----------------------------- +fixed point operator `fix`. It works the same as in +the course materials: it takes a function of type +`(T -> T) -> (T -> T)` as an argument and uses that +for recursive calls. -TODO: div zero -TODO: unclosed parenthesis -TODO: type errors +The factorial function could be implemented as such: +```myslip +(let fact (fix + (fn fact' (Int -> Int) (Int -> Int) + (fn n Int Int + (case n + (1 1) + (_ (* n (fact' (- n 1)))) + ) + ) + ) +)) +``` Exercises -- cgit v1.2.3