Skip to content

Instantly share code, notes, and snippets.

View keleshev's full-sized avatar
🐪

Vladimir Keleshev keleshev

🐪
View GitHub Profile
@keleshev
keleshev / xml.ml
Last active April 16, 2020 08:21
Simple XML pretty-printing in OCaml using Format module
#! /usr/bin/env ocaml
let fprintf = Format.fprintf
type t =
| Tag of {name: string; attributes: (string * string) list; body: t list}
| String of string
let format_attribute f (key, value) = fprintf f " %s=\"%s\"" key value
module Id = struct
let (>>=) value callback =
callback value
let return x = x
let get x = x
end
@keleshev
keleshev / unimo.ml
Last active January 17, 2018 12:49
(* Paper: https://pdfs.semanticscholar.org/6485/84a9a714adc95a103c26d18b54c4aad1c812.pdf *)
module type EFFECT = sig
type 'unimo t
end
module Unimo (Effect : EFFECT) = struct
@keleshev
keleshev / ast.ml
Last active January 17, 2018 13:24
open Printf
module Number = struct
type t = [ `Num of int ]
let eval (`Num n) = n
let to_string (`Num n) = string_of_int n
end
module type MONAD = sig
type 'a t
val return : 'a -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
end
module type MONAD2 = sig
let fix f_nonrec =
let rec f t = f_nonrec f t in
f
module Syntax = struct
module Open = struct
type 'r t = [
| `Unit
| `Boolean of bool
module type MONAD = sig
type 'a t
val return : 'a -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
end
module Option : (MONAD with type 'a t = 'a option) = struct
type 'a t = 'a option
(*
* This file can be executed by running:
* $ ocaml -rectypes map-as-a-recursion-scheme.ml
*
*)
open Printf
(*
let (=>) left right = print_char (if left = right then '.' else 'F')
module Site = struct
type t = int
let max_filenames = 400
module type INLINE_SUM = functor
(Immediate: sig type t end) (Reference: sig type t end) ->
sig
type t