Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
usage_exit() {
die <<EOF
Usage: $0 <query>
Search text in source code from GitHub.
Options:
-h show this help
-f output format {yaml,json,line} (default: yaml)
@tjaskula
tjaskula / PriorityQueue.fs
Created December 9, 2016 00:07
mutable priority queue in F#
open System
open Microsoft.FSharp.Core
// maybe there is a better way to simplify this
let private (|Greater|_|) descendent compareResult =
match compareResult with
| n when n < 0 && descendent -> None
| n when n < 0 && not descendent -> Some()
| 0 -> None
| n when n > 0 && descendent -> Some()
@swlaschin
swlaschin / ConstrainedTypesExamples.fsx
Last active March 9, 2025 02:36
Examples of creating constrained types in F#
// General hints on defining types with constraints or invariants
//
// Just as in C#, use a private constructor
// and expose "factory" methods that enforce the constraints
//
// In F#, only classes can have private constructors with public members.
//
// If you want to use the record and DU types, the whole type becomes
// private, which means that you also need to provide:
// * a constructor function ("create").
@einblicker
einblicker / gist:1885393
Created February 22, 2012 14:45
F#でGADTsを実現する二つの方法
module FPStyle =
[<AbstractClass>]
type Eq<'A, 'B> private () =
abstract F : 'A -> 'B
abstract G : 'B -> 'A
static member Id<'A>() =
{ new Eq<'A, 'A>() with
member this.F(x) = x
member this.G(x) = x }
@einblicker
einblicker / gist:1240586
Created September 25, 2011 13:09
toy type inference
module ToyTypeInfer
type Var = string
type Expr =
| ENum of int
| EBool of bool
| EVar of Var
| EPlus of Expr * Expr
| EIf of Expr * Expr * Expr