Skip to content

Instantly share code, notes, and snippets.

View brianberns's full-sized avatar

Brian Berns brianberns

View GitHub Profile
@dadhi
dadhi / Env.fsx
Created March 11, 2019 12:51
An F# toy example of Scala ZIO Environment
module EnvDemo
open System
open System.IO
[<Struct>]
type Nothing =
private
| Nothing
@jwosty
jwosty / StateBuilder.fsx
Created March 24, 2016 23:44
F# state monad / computation expression builder, and example usage
open System
open System.IO
type State<'s, 'a> = State of ('s -> ('a * 's))
module State =
let inline run state x = let (State(f)) = x in f state
let get = State(fun s -> s, s)
let put newState = State(fun _ -> (), newState)
let map f s = State(fun (state: 's) ->
@sebfisch
sebfisch / gist:2235780
Created March 29, 2012 10:47
Laymans explanation of delimited continuations with examples of using them for exception handling and nondeterministic programming.

Delimited Continuations

Delimited continuations manipulate the control flow of programs. Similar to control structures like conditionals or loops they allow to deviate from a sequential flow of control.

We use exception handling as another example for control flow manipulation and later show how to implement it using delimited continuations. Finally, we show that nondeterminism can also be expressed using delimited continuations.

Exception Handling