Skip to content

Instantly share code, notes, and snippets.

@praeclarum
praeclarum / AlgorithmW.fs
Last active February 2, 2025 14:29
Algorithm W - or Hindley-Milner polymorphic type inference - in F#
module AlgorithmW
// HINDLEY-MILNER TYPE INFERENCE
// Based on http://catamorph.de/documents/AlgorithmW.pdf
// (Now at http://web.archive.org/web/20170704013532/http://catamorph.de/documents/AlgorithmW.pdf)
type Lit =
| LInt of int
| LBool of bool
@praeclarum
praeclarum / Script.fs
Created August 26, 2015 06:37
Scripting language in F#
module k
(*
type TypeIdent = string
type TypeExpr = name:string? (string | TypeIdent | Or TypeExpr TypeExpr | And TypeExpr)
type TypeDecl = Type string TypeExpr
@praeclarum
praeclarum / Script.swift
Last active November 26, 2020 22:31
A little scripting language written in Swift. It supports first class functions (closures) and variable mutation. This code includes the AST, the interpreter, and a JavaScript parser.
//
// Script.swift
//
// Created by Frank A. Krueger on 6/28/15.
// Copyright © 2015 Krueger Systems, Inc. All rights reserved.
//
import Foundation
enum Val {
@queertypes
queertypes / read-dt.org
Last active January 10, 2025 02:25
Implement a Dependently Typed Language and Then Some
@jeapostrophe
jeapostrophe / ab.log
Created April 28, 2015 10:52
Responding to requests concurrently in the Racket Web server
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software: Racket
Server Hostname: localhost
Server Port: 9000
@jozefg
jozefg / closconv.lhs
Last active June 4, 2025 10:59
Tutorial on Closure Conversion and Lambda Lifting
This is my short-ish tutorial on how to implement closures in
a simple functional language: Foo.
First, some boilerplate.
> {-# LANGUAGE DeriveFunctor, TypeFamilies #-}
> import Control.Applicative
> import Control.Monad.Gen
> import Control.Monad.Writer
> import Data.Functor.Foldable
@bobatkey
bobatkey / STLC.markdown
Last active December 18, 2020 15:59
Three typing rules and the constructive truth

This is a type constructor

class FunctionType:
    def __init__(self, tyA, tyB):
        self.tyA = tyA
        self.tyB = tyB

    def __eq__(self, other):
 return self.tyA == other.tyA and self.tyB == other.tyB
@mflatt
mflatt / functional.rkt
Created January 16, 2014 17:13
Programs by Jay and Matthew at Lambda Lounge Utah, 14 Jan 2014: * "functional.rkt" is from Jay's introduction to functional programming * "web.rkt" and "page.rkt" are from Matthew's explanation of Racket macros & modules
#lang racket
(require rackunit)
;; A singly linked list is either
;; - NULL
;; - pointer to data and a pointer a sll
(struct node (data-ptr next-ptr))
(define n4 (node 4 null))
@jj-issuu
jj-issuu / avl.ml
Created January 14, 2014 07:36
OCaml AVL tree
module AVL = struct
type height = int
type int = height
module Elt = Int32
type t = Leaf | Node of t * Elt.t * t * height
exception Impossible
let height = function
@bobatkey
bobatkey / gadts.sml
Created January 5, 2014 18:34
Encoding of GADTs in SML/NJ
(* This is a demonstration of the use of the SML module system to
encode (Generalized Algebraic Datatypes) GADTs via Church
encodings. The basic idea is to use the Church encoding of GADTs in
System Fomega and translate the System Fomega type into the module
system. As I demonstrate below, this allows things like the
singleton type of booleans, and the equality type, to be
represented.
This was inspired by Jon Sterling's blog post about encoding proofs
in the SML module system: