Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View dhilst's full-sized avatar
😻

Daniel Hilst dhilst

😻
View GitHub Profile
@wteuber
wteuber / gist:8475728
Created January 17, 2014 15:52
use MySQL "ENGINE=MEMORY" for rails app, thanks to http://stackoverflow.com/questions/1602494/rails-with-in-memory-database
find ./db/migrate/* | xargs sed -i 's/create_table [^ ]*/&, :options => "ENGINE=MEMORY"/'
@jozefg
jozefg / closconv.lhs
Last active March 5, 2024 11:52
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
@ast-hugger
ast-hugger / dc.rkt
Last active October 7, 2022 22:59
Delimited continuations in terms of call/cc
;; Delimited continuations
#lang racket ; but will work in any Scheme (without this line)
;; There are other implementations along the same lines floating around.
;; Here we are trying to paint a more comprehensible (or at least a less
;; incomprehensible) picture by structuring the implementation as three
;; distinct layers:
;; Layer 1
from ast import (
NodeTransformer,
arguments,
arg,
Lambda,
parse,
In,
Call,
Expression,
fix_missing_locations,
let valid_cpf cpf =
let aux size =
let sum = ref 0 in
for i = 0 to (size - 2) do
sum := !sum + cpf.(i) * (size - i);
done;
!sum * 10 mod 11
in
(aux 10) == cpf.(9) && (aux 11) == cpf.(10)
type exists<V> = <Y>(p: (v: V) => Y) => Y;
// module interface
type Unique_S<T> = {
next: () => T,
equal: (a: T, b: T) => boolean,
compare: (a: T, b: T) => number,
show: (t: T) => string,
};
type Eq<A, B> = <X>(a: A, eq: (x: A & B) => X) => X;
const refute = (x: never) => x;
const refl = <A, X>(a: A, eq: (x: A) => X) => eq(a);
const sickos = <A>(x: A, eq: Eq<A, number>) => eq(x, (x) => x);
const two = sickos(2, refl);
type Ty<A> =
| { tag: "number"; eq: Eq<A, number> }
| { tag: "string"; eq: Eq<A, string> };