Skip to content
/ Eff Public

A library for programming with Algebraic Effects in F#

Notifications You must be signed in to change notification settings

palladin/Eff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

A library for programming with Algebraic Effects in F#

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages