Giter Club home page Giter Club logo

ruff's Introduction

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

ruff's People

Contributors

dependabot[bot] avatar nymphium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.