Skip to content

Instantly share code, notes, and snippets.

View bryanedds's full-sized avatar

Bryan Edds bryanedds

View GitHub Profile
@bryanedds
bryanedds / Vsync.fs
Last active October 25, 2022 19:49
Vsync rewritten as a monad.
namespace Marvel
open System
open System.Diagnostics
open System.Threading
open System.Threading.Tasks
open Marvel
/// The 'Vsync' (AKA, 'Variable Synchrony') monad.
/// Runs code synchronously when the 'Venom/System/Sync' Consul variable is 'True', in parallel otherwise.
/// NOTE: to reference how all this stuff works in F#, see here - https://msdn.microsoft.com/en-us/library/dd233182.aspx
@bryanedds
bryanedds / Vsync.fs
Last active October 24, 2016 21:32
The 'Vsync' (AKA, 'Variable Synchronization') computation expression that coheres into the Sync comp. expr. when SYNC is #defined, and into the Async comp. expr. otherwise.
namespace YourNamespaceHere
open System
open System.Diagnostics
open System.Threading
open System.Threading.Tasks
/// The 'Sync' builder for evaluating expressions in a synchronous style to aid debugging.
type [<Sealed>] Sync () =
member inline this.Bind (x, f) = f x
member inline this.Return x = x
open System
open FSharpx.Reader
[<AutoOpen>]
module LoggerModule =
/// A fake logger type.
type Logger =
private { __ : unit }
@bryanedds
bryanedds / Pure ADT State.fs
Last active August 13, 2016 11:09
Pure ADT State
open FSharpx.State
/// A tic-tac-toe piece, or the absence thereof.
type Piece = U | X | O
/// Tic-tac-toe board position.
type Position = { X : int; Y : int }
[<AutoOpen>]
module GameModule =
/// A tic-tac-toe piece, or the absence thereof.
type Piece = U | X | O
/// Tic-tac-toe board position.
type Position = { X : int; Y : int }
[<AutoOpen>]
module GameModule =
/// A tic-tac-toe game implemented as a Pure ADT.
open System
[<AutoOpen>]
module LoggerModule =
/// A fake logger type.
type Logger =
private { __ : unit }
[<RequireQualifiedAccess; CompilationRepresentation (CompilationRepresentationFlags.ModuleSuffix)>]
namespace Prime
open System
[<AutoOpen>]
module RandModule =
/// Implements an immutable random number generator using the xorshift* algorithm.
/// NOTE: this is POORLY tested - would not recommend using until tested properly!
type [<StructuralEquality; NoComparison>] Rand =
{ Current : uint64 }
@bryanedds
bryanedds / gist:3f7d60169a8316835bfa
Created November 6, 2014 16:05
And yet somehow I'm confident that this will actually run properly the first time...
let product address (observable : 'a Observable) : ('a * 'b) Observable =
let subscribe = fun world ->
let subscriptionKey = World.makeSubscriptionKey ()
let subscriptionKey' = World.makeSubscriptionKey ()
let subscriptionAddress = !+ [acstring subscriptionKey]
let subscriptionAddress' = !+ [acstring subscriptionKey']
let (address', unsubscribe, world) = observable.Subscribe world
let unsubscribe = fun world ->
let world = unsubscribe world
let world = World.unsubscribe subscriptionKey world