Skip to content

Instantly share code, notes, and snippets.

@camlspotter
camlspotter / haha.md
Last active Jul 4, 2018
OCaml zippy tutorial in Japanese
View x.ml
(** Generation of typerep methods for tag-checking *)
(* XXX simply moved to sig.ml ? *)
open Typerep_lib.Std
module Sig = struct
open Sig
type res = [%import: Sig.res]
and ftypekind = [%import: Sig.ftypekind]
View hoge.ml
match x with
| OpeExp (e1, op, e2) ->
begin match op with
| Plus -> ...
| Minus -> ...
end
| Root (e1, e2) -> ...
View gist:d8e9492373739f300d35
(let
((Fib/0
(let*
((fib/1008
(lambda (n/1009)
(if (not (equal n/1009 0))
(if (not(equal n/1009 1))
(+ (funcall fib/1008 (- n/1009 1)) (funcall fib/1008 (- n/1009 2)))
1)
0))))
@camlspotter
camlspotter / gist:6c8a70ddd2b5fce04d6a
Last active Oct 14, 2015
How fib is compiled in OCaml, and a hand compilation of it to Elisp
View gist:6c8a70ddd2b5fce04d6a
let rec fib = function | 0 -> 0 | 1 -> 1 | n -> fib (n-1) + fib (n-2)
(* Output of -dlambda *)
(setglobal Fib!
(letrec
(fib/1008
(function n/1009
(if (!= n/1009 0)
(if (!= n/1009 1)
View gist:a8952a5fdf7298c59b9b
open Format
let rec hovb ppf = function
| 0 -> ()
| n ->
fprintf ppf "(@[<hov>-----------------------------------%03d@," n;
hovb ppf (n-1);
fprintf ppf "@])"
let rec b ppf = function
@camlspotter
camlspotter / 4.02.3+curried-constr.diff
Created Sep 1, 2015
DIFF between OCaml 4.02.3 and 4.02.3+curried-constr
View 4.02.3+curried-constr.diff
diff --git a/README_curried_constr.md b/README_curried_constr.md
new file mode 100644
index 0000000..12ed175
--- /dev/null
+++ b/README_curried_constr.md
@@ -0,0 +1,66 @@
+Variant constructors as functions
+==================================
+
+Suppose we have:
View recrec.ml
(*
ocamlfind ocamlopt -o recrec -package compiler-libs.common -linkpkg recrec.ml
*)
open List
open Format
let (&) = (@@)
module I() = TypedtreeIter.MakeIterator(struct
View gist:1f08efcd2a1fb7daef83
let (&) = (@@)
module Array = struct
include Array
let fold_lefti f st a =
let st = ref st in
Array.iteri (fun i a -> st := f !st i a) a;
!st
end
View gist:4d963db5b9af8e7ddfd5
type t =
| Pair of t * t
| Number of int
| Function of string (* or what? *)
let rec empty = Pair (empty, empty) (* make a looped value *)
let is_empty t = match t with
| Pair (t1, t2) -> t == t1 && t == t2 (* using pointer equality *)
| _ -> false
You can’t perform that action at this time.