Project

ruff

0.01
No commit activity in last 3 years
No release in over 3 years
ONE-SHOT Algebraic Effects for Ruby!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 13.0
 Project Readme

ruff

Gem Version

ONE-SHOT Algebraic Effects Library for Ruby!

require "ruff"

Double = Ruff.instance
Triple = Ruff.instance
Log = Ruff.instance

h1 = Ruff.handler
  .on(Double){|k, v| k[v * 2] }
  .on(Triple){|k, v| k[v * 3] }

h2 = Ruff.handler.on(Log){|k, msg|
  k[]
  puts "logger: #{msg}"
}

h1.run{
  h2.run{
    v = Double.perform 2
    Log.perform (v + 2)
    puts Triple.perform 3
  }
}
# ==> prints
# 9
# logger: 6

Feature

One-shot algebraic effects

You can access the delimited continuation which can run only once. Even the limitation exists, you can write powerful control flow manipulation, like async/await, call1cc.

We have an formal definition for the implementation, by showing a conversion from algebraic effects and handlers to asymmetric coroutines. See here (in Japanese).

Subtyping on effects

You can define an sub effect for another effect. It enables to make an effect hierarchy, such as Exceptions in Java. This implementation is based on a calculus λσ<: (Description (in Japanese)).

Pre-defined effect and handlers

We provide some ready-to-use effect and handlers. You can use quickly powerful control flows.

LICENSE

MIT