Skip to content

Instantly share code, notes, and snippets.

type State<'a, 's> = ('s -> 'a * 's)
module State =
// Explicit
// let result x : State<'a, 's> = fun s -> x, s
// Less explicit but works better with other, existing functions:
let result x s =
x, s
let bind (f:'a -> State<'b, 's>) (m:State<'a, 's>) : State<'b, 's> =
/// State is a function type that takes a state and
/// returns a value and the new state.
/// Single case union of the same type.
type State<'a, 's> = ('s -> 'a * 's)
module State =
// Explicit
// let result x : State<'a, 's> = fun s -> x, s
// Less explicit but works better with other, existing functions:
let result x s =
type StateId = StateId of int
type PlanId = PlanId of int
type StepId = StepId of int
type State = {
LastStateId : StateId
LastPlanId : PlanId
LastStepId : StepId
}
type Step =
type Food =
| Chicken
| Rice
type Step<'next> =
| GetFood of Food * 'next
| Eat of Food * 'next
| Sleep of hours:int * 'next
module Step =
type BuilderTest () =
member this.Yield (evalResult: bool) =
evalResult
member this.For(source: seq<'a>, body:'a -> seq<'b * bool>) =
source
|> Seq.collect (fun x -> body x |> Seq.map (fun (idx, expr) -> (x, idx), expr))
member this.For(source: seq<'a>, body:'a -> bool) =
source |> Seq.map (fun x -> x, body x)
@matthewcrews
matthewcrews / 0_reuse_code.js
Created September 7, 2017 03:05
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console