Skip to content

Instantly share code, notes, and snippets.

View gist:b2c2adc5a9ffc60af5912ad02dc76d35
module rec Value : sig
type t =
| Int of int
| Tbl of t ValueTbl.t
val hash : t -> int
val equal : t -> t -> bool
end = struct
type t =
| Int of int
| Tbl of t ValueTbl.t
View scope.ml
type var = string
module Term = struct
type t =
| Int of int
| Lam of var * t
| Var of var
| App of t * t
end
View test.ml
type xy_part = [`X of int | `Y of bool]
type pre = [xy_part | `Pcon of pre * pre];;
let rec pcon_to_lstm (arg: pre) : xy_part list =
match arg with
| `Pcon (a, b) -> (pcon_to_lstm a) @ (pcon_to_lstm b)
| (#xy_part as x) -> [x]
View test.ml
type x_part = [`X of int]
type pre = [x_part | `Pcon of pre * pre];;
let rec pcon_to_lstm (arg: pre) : ([`X of int]) list =
match arg with
| `Pcon (a, b) -> (pcon_to_lstm a) @ (pcon_to_lstm b)
| (#x_part as x) -> [x]
View test.ml
let rec filter_map f = function
| [] -> []
| x::xs ->
match f x with
| Some y -> y::filter_map f xs
| None -> filter_map f xs
let list =
filter_map (function `G a -> Some (`G a) | _ -> None)
[`G 0; `F "wat"]
View test.ml
let filter xs =
List.filter (function `G a -> true | _ -> false) xs
let rec refine (xs : [> `G of 'a] list) : [`G of 'a] list =
match xs with
| [] -> []
| ((`G _) as elt)::rest -> elt::refine rest
| _::_ -> assert false
let argtest = [`X(`True);`G(`False)];;
View unicode-bits.txt
╭───┬───╮ ╭───┬───╮ ╭───┬───╮
│ x │ ╶────► y │ ╶────► z │ │
╰───┴───╯ ╰─▲─┴───╯ ╰───┴───╯
╭───┬─│─╮
│ q │ ╵ │
╰───┴───╯
View test.ml
type instruction =
| Order of {id: int; price: float; size: int}
| Cancel of {id: int}
| Cancel_replace of {id: int; new_price: float; new_size: int}
let filter_by_oid instructions oid =
List.filter (function
| Order o -> o.id = oid
| Cancel c -> c.id = oid
| Cancel_replace cr -> cr.id = oid)
View diffTrie.ml
let most_significant_bit =
(-1) lxor ((-1) lsr 1)
let bprint_int_binary buf n =
Buffer.add_string buf "0b";
let rec loop started bit n =
if bit = 0 then begin
if not started then Buffer.add_char buf '0'
end
else
View diffTrie.ml
let most_significant_bit =
max_int lxor (max_int lsr 1)
let print_int_binary n =
print_string "0b";
let rec loop started bit n =
if bit = 0 then ()
else
let b = n land bit in
if b = 0 then begin