Skip to content

Instantly share code, notes, and snippets.

@hcarty
hcarty / refmt.md
Created October 3, 2017 19:05
refmt >>= examples

Using 1.13.7

$ echo 'x >>= fun y -> y >>= fun z -> a' | refmt --parse=ml --print=re -w 10
x
>>= (
  fun
  y =>
    y
 >>= (
@hcarty
hcarty / merlin.log
Created July 26, 2017 16:45
merlin debug log
# 0.50 Mconfig - normalize
{
"ocaml": {
"include_dirs": [],
"no_std_include": false,
"unsafe": false,
"classic": false,
"principal": false,
"real_paths": false,
@hcarty
hcarty / opam_jbuilder_workflow.md
Created May 24, 2017 18:59
Notes on a potentially useful opam + jbuilder workflow

OCaml project workflow using opam and jbuilder

The basic idea is to use opam switches to setup per-OCaml-version shared tools (merlin, ocp-index/ocp-browser, ocp-indent) with project-local builds for everything else.

For example, a user would have a 4.04.1+flambda switch available with its own merlin, ocp-indent and other project-generic tooling.

Then a user would clone or create the project (let's call it Project A (PA)) they are working on. This project would use jbuilder as its build system and include appropriate *.opam files specifying dependencies.

A jbuilder init or jbuilder init-deps command could be available which would pull down the source code for all of PA's transitive dependencies, unpacking them under a local directory _vendor (or some other appropriate name). This _vendor directory could live within a switch-specific context. opam could/would be used to determine the appropriate dependencies to pull down. All of the depedencies would either use jbuilder as their

@hcarty
hcarty / msgpack_precise.ml
Last active July 5, 2016 15:06
msgpack using angstrom - a preview/WIP
open Angstrom
type t =
| Nil
| Bool of bool
| Int_fix_pos of int
| Int_fix_neg of int
| Int8 of int
| Int16 of int
| Int32 of int32
@hcarty
hcarty / mwt.ml
Created June 24, 2016 19:32
Medium-weight threads?
(* Based on module lwt_preemptive.ml from Lwt which is
* Copyright (C) 2005 Nataliya Guts, Vincent Balat, Jérôme Vouillon
* Laboratoire PPS - CNRS Université Paris Diderot
* 2009 Jérémie Dimino
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exceptions;
* either version 2.1 of the License, or (at your option) any later version.
* See COPYING file for details.
@hcarty
hcarty / test.ml
Created June 21, 2016 20:43
Test to see if Lwt.async calls before Lwt_main.run work as intended
let () =
Lwt.async (fun () -> while%lwt true do Lwt_unix.sleep 1.0>> Lwt_io.printl "Hello" done);
Lwt_main.run @@ Lwt_unix.sleep 10.0
@hcarty
hcarty / cmd_terms.ml
Last active June 16, 2016 16:41
Example cmdliner terms
(* Cmdliner goodies *)
open Cmdliner
let make_config host sub accept respond =
{ My_library_sockets.host; sub; accept; respond }
let host =
let doc = "host IP address" in
let docv = "HOST" in
@hcarty
hcarty / oasis2merlin.ml
Created April 28, 2016 20:01
Simple/stupid _oasis -> .merlin
let get_findlib = function
| OASISTypes.FindlibPackage (findlib, _) -> Some findlib
| OASISTypes.InternalLibrary _ -> None
let get_build_deps { OASISTypes.bs_build_depends; _ } =
List.map get_findlib bs_build_depends
let get_build = function
| OASISTypes.Library (_, build, _)
| OASISTypes.Object (_, build, _)
@hcarty
hcarty / .vimrc
Created March 31, 2016 16:51
My .vimrc
set nocompatible
filetype off
" Vundle and its packages
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
@hcarty
hcarty / Makefile
Last active August 11, 2017 10:57
ppx_defer example
all:
ocamlbuild -use-ocamlfind -package ppx_tools,ppx_tools.metaquot ppx_defer.native
ocamlfind ppx_tools/rewriter ./ppx_defer.native test.ml
ocamlfind c -ppx ./ppx_defer.native test2.ml