Skip to content

Instantly share code, notes, and snippets.

View thomasd16's full-sized avatar

Thomas Devries thomasd16

  • Holland Michigan
View GitHub Profile
namespace ConsoleApp1
{
public struct Evil : IMutable
{
public int Value { get; set; }
}
public interface IMutable
{
int Value { get; set; }
}
@thomasd16
thomasd16 / running.fs
Created July 17, 2017 22:27
Full Trampoline monad
//This just weves the prepareStackFree function in through the running function
//what we end up with is what looks like a nested monad
type 't Running =
|Result of 't
|Step of (unit->'t Running)
type 't RunningBuilder = RunningBuilder of ((('t->'t RunningBuilder) list)->'t Running)
type RunningMonad() =
member this.Bind(RunningBuilder expr,fn) =
RunningBuilder(fun stack-> Step(fun()->expr(fn::stack)))
member this.Delay(fn) =
//This just weves the prepareStackFree function in through the running function
//what we end up with is what looks like a nested monad
type 't Running =
|Result of 't
|Step of (unit->'t Running)
type 't RunningBuilder = RunningBuilder of ((('t->'t RunningBuilder) list)->'t Running)
type RunningMonad() =
member this.Bind(RunningBuilder expr,fn) =
RunningBuilder(fun stack-> Step(fun()->expr(fn::stack)))
member this.Delay(fn) =