Skip to content

Instantly share code, notes, and snippets.

View darranhayes's full-sized avatar

Darran Hayes darranhayes

View GitHub Profile
@Savelenko
Savelenko / PhantomProof.fs
Last active August 25, 2022 13:39
Open phantom types with proof
namespace PhantomTypes
module Phantom =
// Private, so must use function 'prove'.
type ProofOf<'a> = private | ProofOfA
// A module proves that it can construct values of type 'a' by providing a value to this function.
let prove (_ : 'a) : ProofOf<'a> = ProofOfA
@Savelenko
Savelenko / GADTMotivation.fs
Last active June 20, 2025 21:38
Motivated simulation of GADTs in F#, quite motivational
module GADTMotivation
(*
Here is a simple motivational example for GADTs and their usefulness for library design and domain modeling. Suppose we
need to work with settings which can be displayed and adjusted in a GUI. The set of possible setting "types" is fixed
and known in advance: integers, strings and booleans (check-boxes).
The GUI should show an example value for each possible setting type, e.g. 1337 for an integer setting and "Hello" for a
string setting. How can we model this small domain of setting types and computing example values?
*)
@dsyme
dsyme / rant.md
Last active January 15, 2025 05:46
@akhansari
akhansari / event-sourced-user.fsx
Last active December 16, 2022 00:09
F# : Event Sourcing in a nutshell
// ========= Event Sourcing in a nutshell
(*
FriendlyName: string
Aggregate friendly name.
Initial: 'State
Initial (empty) state we will start with.
Decide: 'Command -> 'State -> 'Event list
@JordanMarr
JordanMarr / DragDropPage.fs
Last active October 11, 2024 06:00
Fable bindings for "react-dnd" using HTML5 provider
module DragDropPage
open Feliz
open Fable.React
open Fable.React.Props
open ReactDND
type Language = {
Name: string
}
@swlaschin
swlaschin / effective-fsharp.md
Last active September 17, 2025 06:47
Effective F#, tips and tricks

Architecture

  • Use Onion architecture

    • Dependencies go inwards. That is, the Core domain doesn't know about outside layers
  • Use pipeline model to implement workflows/use-cases/stories

    • Business logic makes decisions
    • IO does storage with minimal logic
    • Keep Business logic and IO separate
  • Keep IO at edges

@adymitruk
adymitruk / eventstore.cs
Last active January 6, 2021 02:39
simple event store in #0tech c#
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.Serialization;
using System.Linq;
using domain;
@chrishorton
chrishorton / hangmanwordbank.py
Created May 21, 2017 17:16
Hangman ascii art and wordbank
HANGMANPICS = ['''
+---+
| |
|
|
|
|
=========''', '''
+---+
@anubhavshrimal
anubhavshrimal / CountryCodes.json
Last active November 1, 2025 20:46 — forked from Goles/CountryCodes.json
Country and Dial or Phone codes in JSON format
[
{
"name": "Afghanistan",
"dial_code": "+93",
"code": "AF"
},
{
"name": "Aland Islands",
"dial_code": "+358",
"code": "AX"
@jwosty
jwosty / StateBuilder.fsx
Created March 24, 2016 23:44
F# state monad / computation expression builder, and example usage
open System
open System.IO
type State<'s, 'a> = State of ('s -> ('a * 's))
module State =
let inline run state x = let (State(f)) = x in f state
let get = State(fun s -> s, s)
let put newState = State(fun _ -> (), newState)
let map f s = State(fun (state: 's) ->