unison/unison-src/tests/pattern-matching.u
2023-02-27 11:13:10 -05:00

53 lines
981 B
Plaintext

structural type Foo0 = Foo0
structural type Foo1 a = Foo1 a
structural type Foo2 a b = Foo2 a b
structural type Foo3 a b c = Foo3 a b c
structural type List a = Nil | Cons a (List a)
use Foo0 Foo0
use Foo1 Foo1
use Foo2 Foo2
x = match Foo0 with
Foo0 -> 1
y = match Foo1 1 with
Foo1 1 -> 0
Foo1 _ -> 10
z = match Foo2 1 "hi" with
Foo2 1 _ -> 1
Foo2 x _ -> x
w = match Foo3.Foo3 1 2 "bye" with
Foo3.Foo3 1 2 x -> x Text.++ "bye"
_ -> ""
w2 = cases
Foo3.Foo3 1 4 x -> x Text.++ "bye"
Foo3.Foo3 x y z -> z Text.++ z
len : List a -> Nat
len = cases
List.Nil -> 0
List.Cons _ t -> len t + 1
foo = cases
List.Cons h t
| h > 10 ->
x = 3124
y = 230
x + y
| h < 10 -> 10
| otherwise -> 11
List.Nil -> 0
foo2 = cases
List.Cons h t | h > 10 -> 1
| h < 10 -> 2
| otherwise -> 3
List.Nil -> 0
> (w, w2 (Foo3 1 4 "bye"), len (List.Cons 1 List.Nil), foo (List.Cons 0 List.Nil), foo2 List.Nil)