Skip to content

Latest commit

 

History

History
78 lines (56 loc) · 3.9 KB

README.md

File metadata and controls

78 lines (56 loc) · 3.9 KB

Nuget

EffFs

F# Effect System based on SRTP.
Caution: Multiple handlers cannot be composed.

SharpLab compilation result of example.fsx

Installation

Example

And more examples

#load "../src/EffFs/EffFs.fs"
open EffFs

type RandomInt = RandomInt of int with
  static member Effect(_) = Eff.marker<int>

type Logging = Logging of string with
  static member Effect(_) = Eff.marker<unit>

let inline foo() = eff {
  let! a = RandomInt 100
  do! Logging (sprintf "%d" a)
  let b = a + a
  return (a, b)
}

let rand = System.Random()

type Handler = Handler with
  static member inline Value(_, x) = x

  static member inline Handle(RandomInt a, k) =
    rand.Next(a) |> k

  static member inline Handle(Logging s, k) =
    printfn "[Log] %s" s; k()

foo()
|> Eff.handle Handler
|> printfn "%A"


// example output
(*
[Log] 66
(66, 132)
*)

Build

.NET 5.0 or later is required.

$ dotnet build src/EffFs # Debug
$ dotnet build src/EffFs -c Release

Examples

$ dotnet fsi --exec example/example.fs

Make Nuget Package

$ # edit RELEASE_NOTES.md
$ dotnet fake build -t assemblyinfo
$ dotnet fake build -t pack