Skip to content

Instantly share code, notes, and snippets.

View bryanedds's full-sized avatar

Bryan Edds bryanedds

View GitHub Profile
@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
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 }
open System
[<AutoOpen>]
module LoggerModule =
/// A fake logger type.
type Logger =
private { __ : unit }
[<RequireQualifiedAccess; CompilationRepresentation (CompilationRepresentationFlags.ModuleSuffix)>]
/// 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.
@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 =
open System
open FSharpx.Reader
[<AutoOpen>]
module LoggerModule =
/// A fake logger type.
type Logger =
private { __ : unit }
@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
@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 / gist:b07244c4215ebf38b5dd
Last active September 6, 2015 23:49
Fuck... 118 TODOs...
Find all "TODO", Match case, Whole word, Subfolders, Find Results 1, Entire Solution, ""
C:\FPWorks\Nu\Nu\Nu\RQueue.fs(12): /// TODO: replace all usage with Queue from FSharpx.Collections.
C:\FPWorks\Nu\Nu\Nu\Address.fs(15):/// TODO: implement custom comparison.
C:\FPWorks\Nu\Nu\Nu\Math.fs(12):/// TODO: for consistency with other math constructs, consider making this a struct.
C:\FPWorks\Nu\Nu\Nu\Math.fs(118): /// TODO: See if we can expose an SDL_RenderCopyEx from SDL2(#) that takes floats instead.
C:\FPWorks\Nu\Nu\Nu\Overlay.fs(116): // TODO: see if this can be decomposed
C:\FPWorks\Nu\Nu\Nu\Assets.fs(28):/// TODO: consider if we could / should use a TypeCarrier (phantom type) here.
C:\FPWorks\Nu\Nu\Nu\Assets.fs(200): /// TODO: test this function!
C:\FPWorks\Nu\Nu\Nu\Assets.fs(241): /// TODO: test this function!
C:\FPWorks\Nu\Nu\Nu\Physics.fs(538): /// TODO: see if AlgebraicConverter can be used here instead of this shitty custom syntax.
// Nu Game Engine.
// Copyright (C) Bryan Edds, 2013-2015.
namespace Nu
open System
open System.IO
open System.Xml
open OpenTK
open Prime
open Nu