From 5d447cb520145cc85461070db9d3dbf38fdbc953 Mon Sep 17 00:00:00 2001 From: Alexander Nutz Date: Fri, 12 Sep 2025 10:20:24 +0200 Subject: [PATCH] v0.0.3: no untagged or mixed tagged unions anymore --- spec.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec.md b/spec.md index 8f7ae82..45ff57c 100644 --- a/spec.md +++ b/spec.md @@ -84,26 +84,26 @@ def example3() : User { } ``` -## mixed-tagged union types +## (tagged) union types ``` type Option[t] = - 'Err Unit # Unit that has tag enum 'Err -| t # has no tag + 'Err # If no type specified after tag, defaults to Unit +| 'Some t -# the tags of unions are weakly attached to the types, but won't decay unless they have to *) +# the tags of unions are weakly attached to the types, but won't decay unless they have to def example(n: Num) : Num { let x = 'MyTag n # type of x is 'MyTag Num x # tag gets removed because target type is Num } def example2(n: Num) : Option[Num] { - n # this works, because the `t` is not tagged in option + 'Some n } def example3-invalid() : Option[Num] { - Unit # error: can't convert type `Unit` into type `'Err Unit | t` + Unit # error: can't convert type `Unit` into type `'Err Unit | 'Some Num` # Either label the expression with 'Err, - # or change the return type to Option[Unit] + # or change the return type to Option[Unit], and label the expression with 'Some } def exampe4(): Option[Num] { @@ -116,8 +116,8 @@ def exampe4(): Option[Num] { def example5-error(): Option[Num] { let x = ( 'Err Unit ) :: Option[Unit] x - # error: can't convert type `'Err Unit | Unit` into type `'Err Unit | Num` - # The case `Unit` does not exist in the target `'Err Unit | Num` + # error: can't convert type `'Err Unit | 'Some Unit` into type `'Err Unit | 'Some Num` + # The case `'Some Unit` does not exist in the target `'Err Unit | 'Some Num` } def example6-error(): Option[Unit] { @@ -126,7 +126,7 @@ def example6-error(): Option[Unit] { # in this case, the enum tag does not decay, like in `example`, # because we are casting to an enum - # error: can't convert type `'Error Unit` into type `'Err Unit | Num`` + # error: can't convert type `'Error Unit` into type `'Err Unit | 'Some Num`` # 1st possible solution: manually cast to just `Unit` (via `expr :: Unit`), so that it can convert to the second case of the target # 2nd possible solution: pattern match against the enum, to rename the tag from 'Error to 'Err }