Comparision of JaneStreet Base and OCaml Stdlib
How to use Base
Either use Base selectively:
# #show List.hd;;
let distance' ~bound a b = | |
let n = String.length a and m = String.length b in | |
assert (n >= m); | |
if n - m > bound then None else | |
let fill_bound = min m bound in | |
let previous = Array.make (m + 1) max_int in | |
for j = 0 to fill_bound do previous.(j) <- j done; |
ast.exe: ast.c | |
gcc -Werror -Wswitch -Wimplicit-fallthrough ast.c -o ast.exe | |
clean: | |
rm -f *.o *.exe *.s a.out | |
test.s: ast.exe | |
./ast.exe > test.s |
module Cortege0 = struct | |
type _ t = | |
| [] : unit t | |
| (::) : 'a * 'b t -> ('a -> 'b) t | |
end | |
let printf = Format.printf | |
let fprintf = Format.fprintf | |
let dprintf = Format.dprintf | |
let pp_list ~sep pp = | |
Format.pp_print_list ~pp_sep:(fun ppf () -> Format.fprintf ppf sep) pp | |
let pp_string ppf string = fprintf ppf "%S" string | |
let many = [ |
Either use Base selectively:
# #show List.hd;;
function verboseRegExp(input) { | |
if (input.raw.length !== 1) { | |
throw Error('verboseRegExp: interpolation is not supported'); | |
} | |
let source = input.raw[0]; | |
let regexp = /(?<!\\)\s|[/][/].*|[/][*][\s\S]*[*][/]/g; | |
let result = source.replace(regexp, ''); |
open Printf | |
module Syntax = struct | |
type t = | |
| Unit | |
| Boolean of bool | |
| Number of int | |
| Name of string | |
| Divide of t * t |
%{ | |
#include <stdio.h> | |
#include "parser.h" | |
%} | |
%% | |
[ \r\n\t]* { continue; /* Skip blanks. */ } | |
[0-9]+ { sscanf(yytext, "%d", &yylval->value); | |
return TOKEN_NUMBER; } |
(* | |
* This file can be executed by running: | |
* $ ocaml -rectypes map-as-a-recursion-scheme.ml | |
* | |
*) | |
open Printf | |
(* |
(* https://keleshev.com/advanced-error-handling-in-ocaml *) | |
let failwithf f = Printf.ksprintf failwith f | |
(* | |
t -> bool | int | |
e -> true | false | |
| 0 | 1 | 2 | … |