package safemoney

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module Exchange : sig ... end

Exchange type functor

module Quotient : sig ... end

Quotient type functor

module Discrete : sig ... end

Discrete type functor

Signature for user-defined currency type. Typically one needs to provide the following:

  • currency symbol
  • currency description
  • number of named scales with their value if any

To make custom type module simply implement the Custom signature:

module Custome_Type : Custom = struct
  let symbol = "CSTM"

  let description = "Custom Currency"

  let units =
    let table = Hashtbl.create (module String) in
    let scale1 = Discrete.Scale.make_scale symbol "scale1" (Utils.make_q "1/1") in
    let scale2 = Discrete.Scale.make_scale symbol "scale2" (Utils.make_q "100/1") in
    Hashtbl.set table ~key: "scale1" ~data: scale1;
    Hashtbl.set table ~key: "scale2" ~data: scale2;
    Some table

  let make_qv qv = Quotient.make_qv (symbol, qv)

  let make_dv unit dv =
    match units with
    | Some tbl -> let s = Option.value_exn ~message: "Error retriving non-existent scale" @@ Hashtbl.find tbl unit in Some (Discrete.make_dv (s, dv))
    | None -> None
end
module type Custom = sig ... end
val make_q : string -> Q.t

Convevient helper to make rational Q value

val make_z : string -> Z.t

Convevient helper to make integer Z value

OCaml

Innovation. Community. Security.