#+begin_src elisp tangle: no :results none :exports none (setq pwd (file-name-directory buffer-file-name)) (setq name (file-name-nondirectory (substring buffer-file-name 0 -4))) (setq lib (concat pwd "lib/")) (setq testdir (concat pwd "test/")) (setq mli (concat lib name ".mli")) (setq ml (concat lib name ".ml")) (setq test-ml (concat testdir name ".ml")) (org-babel-tangle) #+end_src * Non-negative float :PROPERTIES: :header-args: :noweb yes :comments both :END: ** Type #+begin_src ocaml :tangle (eval mli) type t = private float #+end_src #+begin_src ocaml :tangle (eval ml) :exports none type t = float #+end_src ** Conversions #+begin_src ocaml :tangle (eval mli) val of_float : float -> t val unsafe_of_float : float -> t val to_float : t -> float val of_string : string -> t val to_string : t -> string #+end_src The ~of_float~ function checks that the float is non-negative. The unsafe variant doesn't do this check. #+begin_src ocaml :tangle (eval ml) :exports none let of_float x = if x < 0. then invalid_arg (__FILE__^": of_float"); x external to_float : t -> float = "%identity" external unsafe_of_float : float -> t = "%identity" let to_string x = let f = to_float x in string_of_float f let of_string x = let f = float_of_string x in of_float f #+end_src