Palladin Eff Save

A library for programming with Algebraic Effects in F#

Project 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.

// 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)
Open Source Agenda is not affiliated with "Palladin Eff" Project. README Source: palladin/Eff
Stars
94
Open Issues
0
Last Commit
6 years ago
Repository

Open Source Agenda Badge

Open Source Agenda Rating