Skip to content

Commit 149f682

Browse files
authored
Merge pull request #8 from Nymphium/simple_impl
significant update
2 parents 7826197 + 5fc5e2a commit 149f682

15 files changed

+201
-777
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ all: test
1616
dependencies:
1717
#) -- $@ --
1818
$(foreach package, $(DEPENDENCIES), \
19-
$(LUAROCKS) install --local $(package);)
19+
[ "$$(luarocks list $(package) --porcelain)" ] || $(LUAROCKS) install --local $(package);)
2020

2121
luacheck: $(SRC_DIR) dependencies
2222
#) -- $@ --

README.md

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $ luarocks --local install eff
1111
```
1212

1313
# usage
14-
`eff` provides four objects, `inst`, `perform`, `handler` and `handlers`.
14+
`eff` provides four objects, `inst`, `perform` and `handler`.
1515

1616
## effect instantiation and invocation
1717
`inst` generates an effect instance.
@@ -23,18 +23,23 @@ perform(Write("Hello!")) -- invocation
2323
```
2424

2525
## effect handler
26-
`handler(eff, value-handler, effect-handler)`
26+
`handler(h)`
2727

28-
`handler` requires the handling effect `eff`, `value-handler` and `effect-handler`, and returns a _handling function_.
28+
`handler` requires a table and returns a _handling function_.
29+
The table has fields, a value handler as `val` and `[Eff]` as an effect handler corresponding to `Eff`.
2930
"Handling an expression with a handler" is translated into an application passing a thunk, containing the expression, to the _handling function_.
3031

3132
```lua
32-
local printh = handler(Write,
33-
function(v) print("printh ended", v) end,
34-
function(k, arg)
35-
print(arg)
36-
k()
37-
end)
33+
local printh = handler {
34+
val = function(v) print("printh ended", v) end,
35+
[Write] = function(k, arg)
36+
print(arg)
37+
k()
38+
end,
39+
[Read] = function(k)
40+
return k("baa")
41+
end
42+
}
3843

3944
printh(function()
4045
local x = perform(Write("hello"))
@@ -47,37 +52,18 @@ printh ended nil
4752
]]
4853
```
4954

50-
`handlers` can handle multiple effects.
51-
Pass `{eff, effect-handler}` tuples to the function
52-
```lua
53-
local someh = handlers(
54-
function(v) return v end, -- value handler
55-
{Foo, function(k, v) print("catch Foo") return k(v) end},
56-
{Bar, function(k, v) print("catch Bar") return k(v) end}
57-
)
58-
```
59-
or you can write such as
60-
```lua
61-
local awesomeh = handlers {
62-
function(v) return v end, -- value handler
63-
-- this is not `[[Foo]]`, just [Foo]. Not a macro, but a standard table syntax.
64-
[Foo] = function(k, v) print("catch foo") return k(v) end,
65-
[Bar] = function(k, v) print("catch bar") return k(v) end,
66-
}
67-
```
68-
69-
### limitation about continuation
55+
### restriction about continuation
7056
The continuation `effect handler` received is *ONE-SHOT*, in other words, the continuatoin *cannot* run more than twice.
7157

7258
```lua
73-
handler(Write,
74-
function(v) print("printh ended", v) end,
75-
function(k, arg)
76-
print(arg)
77-
k()
78-
k() -- call continuation twice
79-
end)
80-
(function()
59+
handler({
60+
val = function(v) print("printh ended", v) end,
61+
[Write] = function(k, arg)
62+
print(arg)
63+
k()
64+
k() -- call continuation twice
65+
end
66+
})(function()
8167
perform(Write("Foo"))
8268
end)
8369

example/example.lua

Lines changed: 0 additions & 66 deletions
This file was deleted.

example/exception.lua

Lines changed: 0 additions & 44 deletions
This file was deleted.

example/go_ctrl.lua

Lines changed: 0 additions & 124 deletions
This file was deleted.

example/monadic_pcall.lua

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)