2020-11-25 21:20:47 +03:00
|
|
|
|
|
|
|
```ucm:hide
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> builtins.merge
|
2020-11-25 21:20:47 +03:00
|
|
|
```
|
|
|
|
|
2020-11-26 05:12:09 +03:00
|
|
|
```unison
|
2021-08-24 21:33:27 +03:00
|
|
|
structural ability X t where
|
2020-11-26 05:12:09 +03:00
|
|
|
x : t -> a -> a
|
|
|
|
|
2021-08-24 21:33:27 +03:00
|
|
|
structural ability Abort where
|
2020-11-26 05:12:09 +03:00
|
|
|
abort : a
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
2020-11-26 05:12:09 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
This code should not type check. The match on X.x ought to introduce a
|
|
|
|
skolem variable `a` such that `c : a` and the continuation has type
|
2020-11-25 21:20:47 +03:00
|
|
|
`a ->{X} b`. Thus, `handle c with h : Optional a`, which is not the
|
|
|
|
correct result type.
|
|
|
|
|
|
|
|
```unison:error
|
2020-11-26 05:12:09 +03:00
|
|
|
h0 : Request {X t} b -> Optional b
|
|
|
|
h0 req = match req with
|
|
|
|
{ X.x _ c -> _ } -> handle c with h0
|
|
|
|
{ d } -> Some d
|
|
|
|
```
|
|
|
|
|
|
|
|
This code should not check because `t` does not match `b`.
|
2020-11-25 21:20:47 +03:00
|
|
|
|
2020-11-26 05:12:09 +03:00
|
|
|
```unison:error
|
|
|
|
h1 : Request {X t} b -> Optional b
|
|
|
|
h1 req = match req with
|
|
|
|
{ X.x t _ -> _ } -> handle t with h1
|
2020-11-25 21:20:47 +03:00
|
|
|
{ d } -> Some d
|
|
|
|
```
|
2020-11-26 05:12:09 +03:00
|
|
|
|
|
|
|
This code should not check for reasons similar to the first example,
|
|
|
|
but with the continuation rather than a parameter.
|
|
|
|
|
|
|
|
```unison:error
|
|
|
|
h2 : Request {Abort} r -> r
|
|
|
|
h2 req = match req with
|
|
|
|
{ Abort.abort -> k } -> handle k 5 with h2
|
|
|
|
{ r } -> r
|
|
|
|
```
|
|
|
|
|
|
|
|
This should work fine.
|
|
|
|
|
|
|
|
```unison
|
|
|
|
h3 : Request {X b, Abort} b -> Optional b
|
|
|
|
h3 = cases
|
|
|
|
{ r } -> Some r
|
|
|
|
{ Abort.abort -> _ } -> None
|
|
|
|
{ X.x b _ -> _ } -> Some b
|
|
|
|
```
|