Skip to content

Instantly share code, notes, and snippets.

View bryanedds's full-sized avatar

Bryan Edds bryanedds

View GitHub Profile
@bryanedds
bryanedds / Injection.cpp
Last active April 19, 2023 11:52
Abstract Data Types and Dependency Injection in C++
#include "functional"
#include "iostream"
#include "string"
namespace proj
{
/// For background on the discussed subject matter, first see this gist article on Abstract Data
/// Types and Alternative Forms of Polymorphism in C++ - https://gist.github.com/bryanedds/6a8ea281bb4a3d8b559e
/// Dependency injection in C++ is easy, if you do it carefully. The quickest way to do it
@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 / Alternative.cpp
Last active August 10, 2020 01:56
Abstract Data Types and Alternative Forms of Polymorphism in C++
#include "functional"
#include "iostream"
namespace proj
{
/// Polymorphism in C++ is typically implemented with dynamic dispatch. On the plus side, it's
/// easy to grasp (initially), well-understood, and works retroactively. On the minus side, it
/// sucks you into OOP quagmires too easily and is not terribly efficient. Knowing about other
/// types of polymorphims may lead you to avoid this approach wherever practical. Places where
/// it's practically unavoidable are those that require user-defined subtypes, such as plugins
open System
[<AutoOpen>]
module LoggerModule =
/// A fake logger type.
type Logger =
private { __ : unit }
[<RequireQualifiedAccess; CompilationRepresentation (CompilationRepresentationFlags.ModuleSuffix)>]
@bryanedds
bryanedds / prime_collections_benchmarks.txt
Last active May 25, 2020 19:24
Prime Collections Benchmarks
Array Compute timings...
Run time: 00:00:00.2584128
Run time: 00:00:00.2624985
Run time: 00:00:00.2559355
Run time: 00:00:00.2585773
UList Compute timings...
Run time: 00:00:00.8482014
Run time: 00:00:00.8477076
Run time: 00:00:00.8356866
Run time: 00:00:00.8330682
namespace OmniBlade
open System
open FSharpx.Collections
open Prime
open Nu
open Nu.Declarative
open OmniBlade
[<AutoOpen>]
module OmniGame =
/// 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 }
/// The game data abstraction.
abstraction Game =
{ FirstPlayerTurn : bool
Board : Map<Position, Piece> }
@bryanedds
bryanedds / gist:3481e73bcb257720daf651272edc864b
Last active June 3, 2019 01:29
Latest example of WIP Nelmish.
type [<NoComparison>] OmniModel =
{ Splash : Screen
Title : Screen
TitleGui : Layer
TitlePlay : Entity
TitleCredits : Entity
TitleExit : Entity
Credits : Screen
CreditsGui : Layer
CreditsBack : Entity
namespace OmniBlade
open Prime
open Nu
open OmniBlade
[<AutoOpen>]
module OmniGame =
type [<NoComparison>] OmniModel =
{ Omniscreen : Screen
[<AutoOpen>]
module GelmDispatcherModule =
type [<NoEquality; NoComparison>] Binding<'m, 's when 's :> Simulant> =
{ Address : Address<obj>
AddressType : Type
MakeMessage : Event<obj, 's> -> 'm option }
type [<NoEquality; NoComparison>] Binding<'m, 'e, 's when 's :> Simulant> =
| Binding of Binding<'m, 's>