Skip to content

Instantly share code, notes, and snippets.

@hcarty
hcarty / indexMap.ml
Last active December 14, 2015 09:39
Generic indexables
See hcarty/indexmap for the latest
@hcarty
hcarty / link.rpath
Last active December 15, 2015 03:59
ocamlbuild plugin - support rpath and "-static" when linking
open Ocamlbuild_plugin
let () = dispatch begin function
| After_rules ->
rule "atdgen: .atd -> _t.ml*, _j.ml*, _v.ml*"
~prods:["%_t.ml";"%_t.mli";"%_j.ml";"%_j.mli";"%_v.ml";"%_v.mli";]
~dep:"%.atd"
(begin fun env build ->
let atdgen = "atdgen" in
Seq [
@hcarty
hcarty / lwt_promise.ml
Created June 26, 2013 02:37
Playing around with Lwt + something promise-y/future-y
let ( >>= ) = Lwt.( >>= )
let promise f x =
let mbox = Lwt_mvar.create_empty () in
Lwt.async (
fun () ->
f x >>= fun y ->
Lwt_mvar.put mbox y
);
mbox
@hcarty
hcarty / lwt_indexed_io.ml
Last active January 25, 2016 02:55
Lwt friendly mmap-like I/O
let ( >>= ) = Lwt.( >>= )
let ( >|= ) = Lwt.( >|= )
external identity : 'a -> 'a = "%identity"
module type Src_sig = sig
type t
val read_bytes : t -> size:int -> offset:int -> string option Lwt.t
val write_bytes : t -> string -> offset:int -> unit Lwt.t
@hcarty
hcarty / indexMapGADT.ml
Created July 29, 2013 10:13
GADT-based index map experiment
type read
type write
type no
type (_, _, _) t =
| Read : ('i -> 'e) -> ('i, 'e, (read * no)) t
| Write : ('i -> 'e -> unit) -> ('i, 'e, (no * write)) t
| ReadWrite : ('i -> 'e) * ('i -> 'e -> unit) -> ('i, 'e, (read * write)) t
let make_ro get = Read get
@hcarty
hcarty / makemod.ml
Created August 29, 2013 15:18
Modules from modules
module type S = sig
type t
end
module type Sout = sig
type a
type b
type t = A of a | B of b
end
@hcarty
hcarty / batSet.ml
Created January 20, 2014 17:01
BatSet infix operator possibilities
(* In the context of BatSet and BatSet.Make *)
module Infix = struct
let ( <-- ) s x = add x s
let ( < ) a b = not (equal a b) && subset a b
let ( > ) b a = not (equal a b) && subset a b
let ( <= ) a b = subset a b
let ( >= ) b a = subset a b
let ( - ) a b = diff a b
@hcarty
hcarty / add-ppa.sh
Created May 22, 2014 12:58
Travis config (using PPA) for ocaml-zmq
#!/bin/sh -ex
echo 'yes' | sudo apt-add-repository ppa:chris-lea/zeromq
sudo apt-get update
sudo apt-get install libzmq3-dev
@hcarty
hcarty / build.txt
Created March 18, 2015 18:21
ppx_import in .ml from .mli
$ ocamlbuild -classic-display -use-ocamlfind -package ppx_import,ppx_deriving.std test.cma
ocamlfind ocamldep -package ppx_import,ppx_deriving.std -modules test.mli > test.mli.depends
ocamlfind ocamlc -c -package ppx_import,ppx_deriving.std -o test.cmi test.mli
ocamlfind ocamldep -package ppx_import,ppx_deriving.std -modules test.ml > test.ml.depends
ocamlfind ocamlc -c -package ppx_import,ppx_deriving.std -o test.cmo test.ml
+ ocamlfind ocamlc -c -package ppx_import,ppx_deriving.std -o test.cmo test.ml
File "test.ml", line 1, characters 19-25:
Error: Unbound module Test
Command exited with code 2.