Skip to content

Instantly share code, notes, and snippets.

View keleshev's full-sized avatar
🐪

Vladimir Keleshev keleshev

🐪
View GitHub Profile
open Printf
module type GENERIC = sig
type t
val constructor : string -> int -> t list -> t
val string : string -> t
val int : int -> t
end
#! /usr/bin/env ocaml
type some_interface = <
foo : unit -> unit
>
let do_stuff (p : some_interface) =
p#foo ()
@keleshev
keleshev / case.ml
Last active December 18, 2018 21:41
#! /usr/bin/env ocaml
(* From http://keleshev.com/point-free-case-analysis *)
open Printf
let id x = x
let const x _ = x
(*
(* https://www.infoq.com/presentations/Thinking-Parallel-Programming *)
open Printf
let (=>) left right = printf "%c" (if left = right then '.' else 'F')
let print_list list = printf "[%s]" (String.concat "; " list)
let sprint_list list = sprintf "[%s]" (String.concat "; " list)
module Cat = struct
open Printf
let (=>) left right = printf "%c" (if left = right then '.' else 'F')
module CharString = struct
type t = Empty | Char of char * t
let rec fold ~empty ~char = function
| Empty -> empty
  • Package vendoring with OPAM
  • Dual numbers / Automatic differentiation
  • Sumbolic differentiation
  • Pure-functional precedence parsing

  • fold_left as recursion scheme
(* type 'a succ *)
module Slit = struct
type zero
type 'a succ = X
type (_, _) t =
open Printf
let (=>) left right = printf "%c" (if left = right then '.' else 'F')
let print_list list = printf "[%s]" (String.concat "; " list)
let sprint_list list = sprintf "[%s]" (String.concat "; " list)
@keleshev
keleshev / fold.ml
Last active October 15, 2020 16:31
let (=>) left right = print_char (if left = right then '.' else 'F')
open Printf
let id x = x
let const x = fun _ -> x
let sum = List.fold_left (+) 0
let (>>) f g x = g (f x)
let () =
open Printf
module Syntax = struct
type t =
| Unit
| Boolean of bool
| Number of int
| Name of string
| Divide of t * t