Skip to content

Instantly share code, notes, and snippets.

@quantumelixir
quantumelixir / permutations_combinations.py
Created January 15, 2011 10:46
Permutations and Combinations in Python
def permute(l) :
if len(l) == 1 :
yield l
else :
for i in range(len(l)) :
for j in permute(l[:i] + l[i + 1:]) :
yield [l[i]] + j
def combinations(l, r) :
if r == 1 :
@danking
danking / gist:1068185
Created July 6, 2011 19:55
A very simple example showing how to use Racket's lexing and parsing utilities
#lang racket
(require parser-tools/lex
(prefix-in re- parser-tools/lex-sre)
parser-tools/yacc)
(provide (all-defined-out))
(define-tokens a (NUM VAR))
(define-empty-tokens b (+ - EOF LET IN))
(define-lex-trans number
(syntax-rules ()
@arjans
arjans / gist:3259688
Created August 4, 2012 20:16 — forked from janewang/gist:3259652
Y Combinator vs. U Combinator vs. Typical Recursion
// Y combinator
function Y(f) {
return (
(function (x) {
return f(function (v) { return x(x)(v); }); })
(function (x) {
return f(function (v) { return x(x)(v); }); })
);
}
@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:
@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
@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))
@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
@jozefg
jozefg / closconv.lhs
Last active May 5, 2024 19:23
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
@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
@queertypes
queertypes / read-dt.org
Last active March 16, 2024 05:49
Implement a Dependently Typed Language and Then Some