Brainstorming a better Quark API for handling JSON…
namespace json {
interface JSON {
String render();
}
class Null implements JSON {
String render() {}
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 = |
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 (+/-) = |
(* 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 |
Brainstorming a better Quark API for handling JSON…
namespace json {
interface JSON {
String render();
}
class Null implements JSON {
String render() {}
namespace monad {
interface Monad<T> {
Monad<U> `>>=`((T -> Monad<U>) callback);
}
}
namespace optional {
interface Optional: Monad {}
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 = |
#require "lambda-term";; | |
let prompt = LTerm_text.(eval [B_fg (LTerm_style.green); S "# "]);; | |
UTop.prompt := fst (React.S.create prompt);; |
open StdLabels | |
let id x = x | |
let (>>) f g a = g (f a) | |
let for_all ~set f = | |
List.iter ~f:(fun x -> assert (f x)) set | |
let for_all2 ~set f = | |
for_all ~set (fun a -> |