2019-04-11 23:22:11 +03:00
|
|
|
use State get put
|
|
|
|
use Writer tell
|
|
|
|
|
2020-01-18 11:49:15 +03:00
|
|
|
> handle
|
|
|
|
handle replicate 5 main
|
|
|
|
with writerHandler []
|
|
|
|
with stateHandler "hello"
|
|
|
|
|
2019-04-11 23:22:11 +03:00
|
|
|
|
|
|
|
main = '(tell get)
|
|
|
|
|
|
|
|
replicate : Nat -> '{e} () -> {e} ()
|
|
|
|
replicate n x =
|
2021-12-16 02:00:56 +03:00
|
|
|
if Nat.eq n 0 then () else
|
2019-04-11 23:22:11 +03:00
|
|
|
!x
|
2021-12-16 02:00:56 +03:00
|
|
|
replicate (drop n 1) x
|
2019-04-11 23:22:11 +03:00
|
|
|
|
2021-08-24 21:33:27 +03:00
|
|
|
structural ability State a where
|
2019-04-11 23:22:11 +03:00
|
|
|
get : {State a} a
|
|
|
|
put : a -> {State a} ()
|
|
|
|
|
2021-08-24 21:33:27 +03:00
|
|
|
structural ability Writer w where
|
2019-04-11 23:22:11 +03:00
|
|
|
tell : w -> {Writer w} ()
|
|
|
|
|
rename Builtins in initial namespace construction, and update tests
- () -> Unit
- ().() -> Unit.Unit
- Pair -> Tuple
- Pair.Pair -> Tuple.Cons
- Sequence -> List
- Effect -> Request
- {Int,Nat,Float,Text}.{==,<,<=,>,>=} -> {Int,Nat,Float,Text}.{eq,lt,lteq,gt,gteq}
- mark Text.!= as a deprecated builtin
2019-08-22 23:34:12 +03:00
|
|
|
stateHandler : s -> Request {State s} a -> (s, a)
|
2020-02-22 02:48:12 +03:00
|
|
|
stateHandler s = cases
|
2020-01-18 11:49:15 +03:00
|
|
|
{ State.get -> k } -> handle k s with stateHandler s
|
|
|
|
{ State.put s -> k } -> handle k () with stateHandler s
|
2019-04-11 23:22:11 +03:00
|
|
|
{ a } -> (s, a)
|
|
|
|
|
rename Builtins in initial namespace construction, and update tests
- () -> Unit
- ().() -> Unit.Unit
- Pair -> Tuple
- Pair.Pair -> Tuple.Cons
- Sequence -> List
- Effect -> Request
- {Int,Nat,Float,Text}.{==,<,<=,>,>=} -> {Int,Nat,Float,Text}.{eq,lt,lteq,gt,gteq}
- mark Text.!= as a deprecated builtin
2019-08-22 23:34:12 +03:00
|
|
|
writerHandler : [w] -> Request {Writer w} a -> ([w], a)
|
2020-02-22 02:48:12 +03:00
|
|
|
writerHandler ww = cases
|
2021-12-16 02:00:56 +03:00
|
|
|
{ Writer.tell w -> k } -> handle k () with writerHandler (snoc ww w)
|
2019-04-11 23:22:11 +03:00
|
|
|
{ a } -> (ww, a)
|