mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-17 13:27:30 +03:00
1.3 KiB
1.3 KiB
This file tests some obscure issues involved with abilities and over-applied functions.
Stream.fromList : [a] -> '{Stream a} ()
Stream.fromList l _ =
_ = List.map (x -> emit x) l
()
Stream.map : (a -> b) -> '{Stream a} r -> '{Stream b} r
Stream.map f stream = handle !stream with Stream.map.handler f
Stream.map.handler : (a -> b) -> Request {Stream a} r -> '{Stream b} r
Stream.map.handler f = cases
{Stream.emit a -> resume} -> 'let
Stream.emit (f a)
Stream.map f resume ()
{r} -> 'r
increment : Nat -> Nat
increment n = 1 + n
> Stream.toList (Stream.map increment (Stream.fromList [1,2,3]))
> let
s1 = do emit 10
emit 20
emit 30
emit 40
s2 = Stream.map (a -> a * 10) s1
Stream.toList s2
structural ability E where
eff : () -> ()
hh : Request {E} (Nat ->{} r) -> Nat -> r
hh = cases
{eff _ -> k} -> x -> h k x
{x} -> x
h : '{E} (Nat -> r) -> Nat -> r
h k = handle !k with hh
foo : '{E} (Nat -> Nat)
foo _ =
eff ()
x -> 7
> h foo 337
structural ability Over where
over : Nat ->{Over} (Nat -> Nat)
hd = cases
{over m -> k} ->
handle k (n -> m + n) with hd
{x} -> x
delegated _ =
handle over 5 with hd
hmm =
x : Nat
x = delegated () 16789
trace "x" x
x
> hmm