package safemoney

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module type Predefined.CustomSource

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
val symbol : Base.string
val description : Base.string
val make_qv : Q.t -> Quotient.t