standalone exapunks vm in ocaml
1(* This Source Code Form is subject to the terms of the Mozilla Public
2 License, v. 2.0. If a copy of the MPL was not distributed with this
3 file, You can obtain one at https://mozilla.org/MPL/2.0/. *)
4
5(** [(str_mapcat join fn seq)] maps [fn] across the [seq] and concats it with [join].
6 Returns the new string.*)
7let str_mapcat (join : string) (fn : 'a -> string) (seq : 'a list) : string =
8 seq |> List.map fn |> String.concat join
9
10module StringMap = Hashtbl.Make (String)
11module StringSet = Set.Make (String)
12module IntMap = Hashtbl.Make (Int)
13
14let identity foo = foo
15
16let time f x =
17 let t = Sys.time () in
18 let fx = f x in
19 Printf.printf "Execution time: %fs\n" (Sys.time () -. t);
20 fx
21
22let with_return (type ret) f =
23 let exception ReturnEx of ret in
24 let return x = raise_notrace (ReturnEx x) in
25 try f return with
26 | exn -> (
27 match exn with
28 | ReturnEx v -> v
29 | _ -> raise exn)