This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type var = string | |
module Term = struct | |
type t = | |
| Int of int | |
| Lam of var * t | |
| Var of var | |
| App of t * t | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)];; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
╭───┬───╮ ╭───┬───╮ ╭───┬───╮ | |
│ x │ ╶────► y │ ╶────► z │ │ | |
╰───┴───╯ ╰─▲─┴───╯ ╰───┴───╯ | |
│ | |
╭───┬─│─╮ | |
│ q │ ╵ │ | |
╰───┴───╯ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder