Skip to content

Instantly share code, notes, and snippets.

View keleshev's full-sized avatar
🐪

Vladimir Keleshev keleshev

🐪
View GitHub Profile
open Core_kernel.Std
module QuadraticEquation = struct
open Float
type t = {a: float; b: float; c: float}
let discriminant {a; b; c} = b * b - 4.0 * a * c
let root {a; b; c} discriminant (+/-) =

Terminal.ml—excercise terminal capabilities in OCaml

Terminal.ml is meant for exercising terminal capabilities, such as color text and cursor manipulation.

At the moment the only interesting functionality it provides is a type-safe templating language for printing color messages, limited to 16 colors.

If you need a more full-featured terminal manipulation library, lambda-term is recommended.

This release is made to collect feedback on the library API design and implementation. To give feedback, create an issue.

open Core_kernel.Std
let (>>) f g x = g (f x)
module Row = struct
let parse_exn = String.split ~on:',' >> List.map ~f:Float.of_string
let to_string = List.map ~f:Float.to_string >> String.concat ~sep:","
let print = to_string >> print_endline
end
let folder sum line =
(* Merge two pre-sorted lists into another sorted list *)
let rec merge_sorted left right =
match left, right with
| left_head :: left_tail, right_head :: right_tail ->
if left_head < right_head then
left_head :: merge_sorted left_tail right
else
right_head :: merge_sorted left right_tail
| [], rest | rest, [] -> rest
open Core_kernel.Std
module Pair = Tuple2
let (>>) f g x = g (f x)
let (<<) f g x = f (g x)
module Hamming = struct
(* 1 no-dependencies *)
let rec distance ?(accu=0) left right =

Brainstorming a better Quark API for handling JSON…

namespace json {
  interface JSON {
    String render();
  }

  class Null implements JSON {
 String render() {}

Rosetta stone: Quark → Ruby

Example

Quark

namespace monad {
  interface Monad<T> {
    Monad<U> `>>=`((T -> Monad<U>) callback);
  }
}

namespace optional {

 interface Optional: Monad {}

Lorem ipsum

Dolor sit amet.


import foo;
#require "lambda-term";;
let prompt = LTerm_text.(eval [B_fg (LTerm_style.green); S "# "]);;
UTop.prompt := fst (React.S.create prompt);;