diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-16 03:43:23 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-16 03:43:23 +0300 |
commit | 3309cad8c27471f6e3c48a6ecea836ee3f9a3d7e (patch) | |
tree | fb90f164631510c0bc509e43472f68855678ebae | |
parent | 4daf7b149622a16a2271630a19f0833702477a86 (diff) | |
download | myslip-3309cad8c27471f6e3c48a6ecea836ee3f9a3d7e.tar.gz myslip-3309cad8c27471f6e3c48a6ecea836ee3f9a3d7e.zip |
doc: added <> and factorial example to TUTORIAL.md
-rw-r--r-- | TUTORIAL.md | 33 |
1 files 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 |