Skip to content

Instantly share code, notes, and snippets.

@nomaddo
nomaddo / escape.ml
Created November 5, 2014 11:35
escape
# module type S = sig type t val e : t end;;
module type S = sig type t val e : t end
# let f () = (module struct type t = int let e = 14 end : S);;
val f : unit -> (module S) = <fun>
# let module M = (val f () : S) in M.e;;
Characters 33-36:
let module M = (val f () : S) in M.e;;
^^^
Error: This expression has type M.t but an expression was expected of type
M.t
@nomaddo
nomaddo / symbol.ml
Created November 5, 2014 11:36
() as symbol
# type t = () of int;;
type t = () of int
# module F () = struct end;;
module F : functor () -> sig end
@nomaddo
nomaddo / how.ml
Created November 5, 2014 11:39
how to use
# type t = :: of int;;
type t = :: of int
# :: 1;;
Characters 0-2:
:: 1;;
^^
Error: Syntax error
# 1 :: ;;
Characters 5-7:
1 :: ;;
@nomaddo
nomaddo / .merlin
Created November 30, 2014 14:38
merlin configure file
S asmcomp
S asmrun
S bytecomp
S byterun
S driver
S parsing
S stdlib
S tools
S typing
S utils
@nomaddo
nomaddo / arr.ml.s
Created December 12, 2014 13:14
output of ocamlopt -c -S ./arr.ml. arr.ml includes only "let access arr i = arr.(i)
camlArr__access_1008:
.cfi_startproc
subq $8, %rsp
.cfi_adjust_cfa_offset 8
.L101:
movq %rax, %rdi
movq -8(%rdi), %rax
movq %rax, %rsi
shrq $9, %rsi
cmpq %rbx, %rsi
@nomaddo
nomaddo / func.ml
Created December 30, 2014 04:35
functor使うとどれくらい遅いのか実験
module type S = sig
type t
val id : t -> t
val f : t -> t
val g : (t -> t) -> t -> t
end
module F(A:S) = struct
type t = A.t
let f x = A.id (A.g A.f (A.id x))
@nomaddo
nomaddo / Ex3_7.thy
Created May 28, 2015 11:11
Ex3_7の解答
(*
問題はbexpに対してEq (Equal)とLe (LessEqual)を定義して、
bval (Eq a b) s = (aval a s = aval b s) と
bval (Le a b) s = (aval a s <= aval b s)
を証明せよというものです。
*)
theory Ex3_7
imports Main
begin
@nomaddo
nomaddo / except2.ml
Created May 31, 2015 16:04
ベンチマーク&テストコード
open Core_bench
exception Ex1
exception Ex2
let ( ** ) n m =
let rec mul cnt =
if cnt = 0 then 1 else n * mul (cnt - 1) in
mul m
@nomaddo
nomaddo / exept2.s
Last active August 29, 2015 14:22
機械語(一部)
/* fはloop1の内部でループしてる関数 */
camlExept2__f_1464:
.cfi_startproc
.L104:
/* クロージャの環境から定数を持ってきて */
movq 16(%rbx), %rdi
/* 比較 */
cmpq %rdi, %rax
/* 比較結果のフラグで分岐 */
jne .L103
@nomaddo
nomaddo / testjava.ml
Created June 18, 2015 10:26
ocamljavaの例
(* ocamljava -o caml.jar -runtime-parameter runtime-lock=off -I +concurrent -I +javalib javalib.cmja -java-extensions concurrent.cmja unix.cmja ./testjava.ml *)
open JavaPervasives
let size = 1000000
let a = Array.make size 100
let rec tarai x y z =
if x <= y then y