GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Nymphium/eff.lua: ONE-SHOT Algebraic Effects for Lua!

BranchesTags
Open more actions menu

Latest commit

 

History

86 Commits
86 Commits

Folders and files

NameName
Last commit message
Last commit date
.travis
.travis
 
 
spec
spec
 
 
src
src
 
 
.gitignore
.gitignore
 
 
.luacheckrc
.luacheckrc
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
eff-5.0-0.rockspec
eff-5.0-0.rockspec
 
 

Repository files navigation

eff.lua

Build Status

ONE-SHOT Algebraic Effects for Lua!

installation

$ luarocks --local install eff

usage

eff provides four objects, inst, perform and handler.

effect instantiation and invocation

inst generates an effect instance. perform invoke the passed effect.

local Write = inst() -- instantiation
perform(Write("Hello!")) -- invocation

effect handler

handler(h)

handler requires a table and returns a handling function. The table has fields, a value handler as val and [Eff] as an effect handler corresponding to Eff. "Handling an expression with a handler" is translated into an application passing a thunk, containing the expression, to the handling function.

local printh = handler {
  val = function(v) print("printh ended", v) end,
  [Write] = function(k, arg)
      print(arg)
      k()
    end,
  [Read] = function(k)
      return k("baa")
    end
}

printh(function()
  local x = perform(Write("hello"))
  return x
end)

--[[ prints:
hello
printh ended    nil
]]

restriction about continuation

The continuation effect handler received is ONE-SHOT, in other words, the continuatoin cannot run more than twice.

handler({
  val = function(v) print("printh ended", v) end,
  [Write] = function(k, arg)
      print(arg)
      k()
      k() -- call continuation twice
    end
})(function()
  perform(Write("Foo"))
end)

--[[prints
lua: ./eff.lua:91: ./eff.lua:82: continuation cannot be performed twice
stack traceback:
        [C]: in function 'error'
        ./eff.lua:91: in local 'printh'
        ../example/example.lua:28: in main chunk
        [C]: in ?
]]

LICENSE

MIT

About

ONE-SHOT Algebraic Effects for Lua!

logic.cs.tsukuba.ac.jp/~sat/pdf/tfp2020-postsymposium.pdf

Topics

algebraic-effectscoroutineseffeffect-systemlua

Resources

Readme
MIT license
Activity

Stars

50 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.