package smtml

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

Typed Values Representation. This module defines types and utilities for representing values with different numeric types, including integers and floating-point numbers. It also provides functions for type checking, comparison, formatting, and conversion.

Value Types

type t =
  1. | I8 of int
    (*

    8-bit integer.

    *)
  2. | I32 of int32
    (*

    32-bit integer.

    *)
  3. | I64 of int64
    (*

    64-bit integer.

    *)
  4. | F32 of int32
    (*

    32-bit floating-point value, stored as an int32.

    *)
  5. | F64 of int64
    (*

    64-bit floating-point value, stored as an int64.

    *)

The type t represents values with different numeric types.

type printer = [
  1. | `Pretty
    (*

    Human-readable format.

    *)
  2. | `Hexadecimal
    (*

    Hexadecimal representation.

    *)
]

Representation options for value printing.

val type_of : t -> Ty.t

type_of v returns the type of the given value v.

val compare : t -> t -> int

compare v1 v2 provides a total ordering over values of type t. It returns a negative integer if v1 is less than v2, zero if they are equal, and a positive integer if v1 is greater than v2.

val equal : t -> t -> bool

equal v1 v2 returns true if v1 and v2 are equal, otherwise false.

val num_of_bool : bool -> t

num_of_bool b converts a boolean b into an integer value of type t. The exact representation depends on the system's convention, typically 1 for true and 0 for false.

Pretty Printing

val set_default_printer : printer -> unit

set_default_printer p sets the default printer format for displaying values.

val pp : t Fmt.t

pp is a formatter for values of type t, using the currently set printer.

val pp_no_type : t Fmt.t

pp_no_type is a formatter that prints a value of type t without displaying its type.

Serialization

val to_string : t -> string

to_string v converts the value v to a string representation.

val of_string : Ty.t -> string -> (t, [> `Msg of string ]) Smtml_prelude.result

of_string ty s attempts to parse the string s as a value of type ty. Returns Ok v on success, or an error message if parsing fails.

val to_json : t -> Yojson.Basic.t

to_json v converts the value v into a JSON representation.

OCaml

Innovation. Community. Security.