Skip to content

Instantly share code, notes, and snippets.

View yallop's full-sized avatar

Jeremy Yallop yallop

View GitHub Profile
@anandabits
anandabits / HKT.swift
Last active December 25, 2023 00:57
Emulating HKT in Swift
// This example shows how higher-kinded types can be emulated in Swift today.
// It acheives correct typing at the cost of some boilerplate, manual lifting and an existential representation.
// The technique below was directly inspired by the paper Lightweight Higher-Kinded Polymorphism
// by Jeremy Yallop and Leo White found at http://ocamllabs.io/higher/lightweight-higher-kinded-polymorphism.pdf
/// `ConstructorTag` represents a type constructor.
/// `Argument` represents an argument to the type constructor.
struct Apply<ConstructorTag, Argument> {
/// An existential containing a value of `Constructor<Argument>`
/// Where `Constructor` is the type constructor represented by `ConstructorTag`
@leque
leque / freer.ml
Last active September 30, 2021 07:44
Freer monad in OCaml
(*
Requirement: higher, ppx_deriving.show
*)
(*
Lightweight higher-kinded polymorphism
https://ocamllabs.github.io/higher/lightweight-higher-kinded-polymorphism.pdf
*)
open Higher