Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Extensible effects for Scala

License

NotificationsYou must be signed in to change notification settings

marcinzh/skutek

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Skutek has evolved to, and been superseded byTurbolift. Turbolift retains most of features and syntax of Skutek. But it internally, it's no longer based on Eff monad.


Skutek: extensible effects without (heavy) lifting

Skutek (pronounced:skoo-tech) is a framework implementing a monad of extensible effects(a.k.a.One monad to rule them all), based onFreer monad, adapted to leverage specifics of Scala's type system, with main differences being:

  • Use of intersection types in lieu of union types (which Scala doesn't have), to model sets of effects.

  • Use of classic OOP inheritence as the way of extending the monad with new operations.

Build Status

Example

importskutek.abstraction._importskutek.std_effects._objectMainextendsApp {// Declare some effects:caseobjectMyReaderextendsReader[Int]caseobjectMyStateextendsState[Int]caseobjectMyExceptextendsExcept[String]// Create a monadic computation using those effects:valcomputation=for {    a<-MyState.Get    b<-MyReader.Ask    c<- {if (b!=0)Return(a/ b)elseMyExcept.Raise(s"Tried to divide$a by zero")    }    _<-MyState.Put(c)  }yield ()// Create a handler for the above computation, by composing// individual handlers of each requested effect:valhandler=MyExcept.handler<<<!MyState.handler(100).exec<<<!MyReader.handler(3)// Execute the computation using the handler:valresult= handler.run(computation)  println(result)// prints "Right(33)"}

The inferred type ofcomputation above is equivalent to:

Unit!!MyState.typewithMyReader.typewithMyExcept.type

where!! is infix type alias forComputation monad:

Computation[Unit,MyState.typewithMyReader.typewithMyExcept.type]

More usage inexamples directory.

Setup

libraryDependencies+="com.github.marcinzh"%%"skutek-core"%"0.16.0"

Cross built Built for Scala 2.13.

Features

Warning: contains links to partially outdated and somewhat embarrassing manual.

  • Simplicity of use:

    • No need of defining the effect stack upfront.
    • No need of lifting of operations into the monad.
    • Effect subtyping.
  • Simplicity of implementation:

    • No dependencies on external libraries.
    • No clever type-fu, no macros. Mostly immutable OOP style.
  • Practical stuff:

    • Predefined set of basic effects (Reader,Writer, etc.).Read more.
    • Conflict proof: ability for multiple instances of the same type of effect, to coexist in the same effect stack (e.g.State[Int] andState[String]).
    • Potentially parallel execution of effects.Read more.
    • Support forfor comprehension guards, for effects compatible with filtering (e.g.Maybe,Choice).
    • Tested stack safety.
  • Caveats and limitations:

    • General infancy of the project.
    • No Limited possiblity of adapting pre-existing monads as Skutek's effects.
    • Removing effects from the stack (local handling) isn't as easy as adding them.Read more.
    • Rare occurences of false positives by Scala's linter (i.e. "inferredAny").Read more.
    • Using patterns infor comprehensions can trigger surprising compiler errors. It can be mitigated byThis compiler plugin.
    • Lack of performance analysis.
    • Concurrency effect is ahack.

User Manual

WIP. Partially outdated since many breaking chanches in 0.10.0

MANUAL.md

About

Extensible effects for Scala

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp