Skip to content

Instantly share code, notes, and snippets.

View objmagic's full-sized avatar

R Li objmagic

View GitHub Profile
@objmagic
objmagic / fib.tex
Created December 30, 2015 06:07
LaTeX is Turing complete
\newcount \temp \newcount \fone \newcount \ftwo \newcount \counter
\newcommand{\fibonacci}[1]{
\counter=#1
\fone=1
\ftwo=1
\temp=0
\the\fone, \the\ftwo
\fibloop
}
@objmagic
objmagic / g.ml
Created October 30, 2015 18:00
gadt corner
module Propagation = struct
type _ t =
IntLit : int -> int t
| BoolLit : bool -> bool t
let check : type s. s t -> s = function
| IntLit n -> n
| BoolLit b -> b
let check : type s. s t -> s = fun x ->
@objmagic
objmagic / index.html
Last active October 7, 2015 16:44
OCaml/typing
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node {
font: 300 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
fill: #bbb;
}
.node:hover {
@objmagic
objmagic / download-camel.sh
Last active September 22, 2015 01:12
caml-list download
wget http://download.gmane.org/gmane.comp.lang.caml.inria/3399/6399
sleep 60
wget http://download.gmane.org/gmane.comp.lang.caml.inria/6399/9399
sleep 60
wget http://download.gmane.org/gmane.comp.lang.caml.inria/9399/12399
sleep 60
wget http://download.gmane.org/gmane.comp.lang.caml.inria/12399/15399
sleep 60
wget http://download.gmane.org/gmane.comp.lang.caml.inria/15399/18399
sleep 60
@objmagic
objmagic / hlist.ml
Created August 24, 2015 20:01
hlist
module HList = struct
type (_, _) hlist =
| Empty : ('a, 'a) hlist
| Cons : 'c * ('a, 'b) hlist -> ('c -> 'a, 'b) hlist
let cons : type a b c. c -> (a, b) hlist -> (c -> a, b) hlist =
fun h tl -> Cons (h, tl)
let hd : type a b c. (c -> a, b) hlist -> c option = function
| Empty -> None
@objmagic
objmagic / convert.ml
Last active August 29, 2015 14:27
Conversion from applicative general form to applicative normal form
(* by Jeremy Yallop *)
(** The applicative interface *)
module type APPLICATIVE =
sig
type +'a t
val pure : 'a -> 'a t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
end
@objmagic
objmagic / pair.ml
Last active August 29, 2015 14:26
pair parser
(* parser generated from ``let seq_parser = (lit 'c') <~> (lit 'd')`` *)
fun s_178 ->
let res1_182 =
let ix_179 = s_178.Sparser.BasicFParser.index in
let f_180 = Sparser.BasicFParser.Failure s_178 in
if ix_179 < s_178.Sparser.BasicFParser.length
then
let e1_181 = (s_178.Sparser.BasicFParser.input).[ix_179] in
(if e1_181 = 'c'
then
@objmagic
objmagic / note.ml
Last active December 30, 2015 20:56
note
let gen () =
let t2pc = ref (fun _ -> assert false) in
let t3pc = ref (fun _ -> assert false) in
let anonpc = ref (fun _ -> assert false) in
let _ = t2pc := fun s ->
let res1 = !t3pc s in
match res1 with
| Success (arr, s) -> Success ((A arr), s)
| Failure _ ->
@objmagic
objmagic / rec.ml
Created July 19, 2015 21:22
rec.ml
type t2 = A of t3 | C of char and t3 = t2
let rec t2_parser = NT (lazy (
either [(fun arr -> A arr) <*> arr_parser;
((fun c -> C c) <*> lit 'c')]))
and arr_parser = NT (lazy (
(lit '[') >> t2_parser << (lit ']')))
@objmagic
objmagic / typeable.ml
Last active August 29, 2015 14:25
typeable.ml
module Eq = struct
type (_, _) t = Refl : ('a, 'a) t
end
type _ nttype = ..
type 'a typeable = {
constructor : 'a nttype;
eq : 'b. 'b nttype -> ('a, 'b) Eq.t option
}