Skip to content

Instantly share code, notes, and snippets.

class SuperPermutation
CHARS = ('a'..'z').map(&:to_sym)
def initialize(size)
@size = size
@chars = CHARS.take(@size)
@used = {}
@index = Hash.new { |h, k| h[k] = [] }
@chars.permutation.each do |seq|
rule Foldl-0 {
foldl $f $init ∅ = $init
}
rule Foldl-N {
$init $f $head = $init' / foldl $f $init' $tail = $res
------------------------------------------------------
foldl $f $init ($head $tail) = $res
}

Haskell

There follows an extremely rough approximation to Haskell's type checker, written as a logic program. Mostly to explore type inference and syntactic sugar.

For the most part, we won't need a lot of syntactic checks in this implementation, but for terms with no internal structure, like variables and numbers, it's useful to specify their members.

#!/usr/bin/env ruby
require "digest/sha1"
require "fileutils"
require "zlib"
GIT_DIR = ".git"
Commit = Struct.new(:id, :data) do
def self.path(id)
{
"dependencies": {
"babel-core": "*",
"babel-loader": "*",
"babel-preset-env": "*",
"babel-preset-react": "*",
"css-loader": "*",
"react": "*",
"react-dom": "*",
"style-loader": "*",
% vim: ft=prolog
% Parser
% ------
parse(S, T) :- atom_chars(S, C), expr(T, C, []).
expr(E) --> ws, (statement(E) ; type(E)), ws.
@jcoglan
jcoglan / blob.rb
Last active October 10, 2017 22:48
Blob = Struct.new(:oid, :content) do
def type
Database::BLOB
end
def to_s
content
end
end
require "set"
class Index
SIGNATURE = "DIRC"
VERSIONS = [2, 3, 4]
HEADER_SIZE = 12
MIN_ENTRY_SIZE = 64
ENTRY_BLOCK = 8
@jcoglan
jcoglan / set.rb
Created September 23, 2017 17:22
require 'set'
class Foo
def ==(x)
true
end
def eql?(x)
false
end
require 'bundler/setup'
require 'infer'
program = Infer::Prolog.program <<-PL
s --> foo,bar,wiggle.
foo --> [choo].
foo --> foo,foo.
bar --> mar,zar.
mar --> me,my.
me --> [i].