From 52fe4da3b74a3fd1a40dc5f8752aa0b02a8a22a9 Mon Sep 17 00:00:00 2001 From: Alexander Nutz Date: Fri, 12 Sep 2025 10:33:34 +0200 Subject: [PATCH] v0.0.5: recursive / self-referential types --- spec.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/spec.md b/spec.md index 879d065..d045283 100644 --- a/spec.md +++ b/spec.md @@ -132,6 +132,11 @@ def example6-error(): Option[Unit] { } ``` +### pattern 1: labelled arguments +``` +def [t] List.remove_prefix(prefix: List[t], list: 'from List[t]) +``` + ## automatic return types ``` def add(a: Num, b: Num) -> _ { @@ -181,7 +186,17 @@ def example(li: List[Char]) -> {t:Token,rem:List[Char]} { } ``` -## pattern 1: labelled arguments +## recursive data types ``` -def [t] List.remove_prefix(prefix: List[t], list: 'from List[t]) +type List[t] = {head:t, tail:List[t]} +# now you might notice an issue with this +# `type` defines non-distinct type alisases +# so what is the type of this... +# Introducing: type self references +# the above example is the same as this: +type List[t] = &a {head:t, tail:a} + +# example 2: +# a List[List[t]] is just: +&b {head: &a {head:t, tail:a}, tail: b} ``` \ No newline at end of file