https://github.com/palladin/Eff
A library for programming with Algebraic Effects in F#
https://github.com/palladin/Eff
Last synced: 8 months ago
JSON representation
A library for programming with Algebraic Effects in F#
- Host: GitHub
- URL: https://github.com/palladin/Eff
- Owner: palladin
- Created: 2015-08-13T17:48:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-12-18T13:31:24.000Z (about 8 years ago)
- Last Synced: 2025-04-13T02:28:31.142Z (9 months ago)
- Language: F#
- Size: 40 KB
- Stars: 100
- Watchers: 7
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list - Eff
README
# Eff
Eff is a library for programming with Algebraic Effects in F# inspired by the [Eff] programming language and the implementation of Algebraic Effects in [OCaml]-Haskell([1], [2]) and especially from the paper [Eff Directly in OCaml].
``` fsharp
// state effect example
let test () =
eff {
let! x = get ()
do! put (x + 1)
let! y = get ()
do! put (y + y)
return! get ()
}
// state effect handler
let stateHandler (s : 'S) (eff : Eff<#State<'S>, 'T>) : ('T * 'S) =
let rec loop (s : 'S) (effect : Effect) =
match effect with
| :? Get<'S> as get -> loop s (get.K s)
| :? Put<'S> as put -> loop put.Value (put.K ())
| :? Done<'T> as done' -> (done'.Value, s)
| _ -> failwith "Unhandled effect"
loop s (run done' eff)
// Apply state effect and execute
stateHandler 1 (test ()) // (4, 4)
```
[Eff]: http://math.andrej.com/wp-content/uploads/2012/03/eff.pdf
[OCaml]: http://www.lpw25.net/ocaml2015-abs2.pdf
[1]: http://homepages.inf.ed.ac.uk/slindley/papers/handlers.pdf
[2]: http://okmij.org/ftp/Haskell/extensible/more.pdf
[Eff Directly in OCaml]: http://kcsrk.info/papers/eff_ocaml_ml16.pdf