module Opaque: sig endint and string.
This module provides a convenient way to convert int or string types
to abstract types.
Motivation: type int may be used for representing several kinds of
data. Confusion is easy, so we often need to make it abstract,
while keeping:
intopen Opaque and then
use a type parameter to define
the specialized version of int or string.
We will write the type declarations as
type port = [`Port] int_t or type date = [`Date] int_t.
Data is converted with the int_t and t_int polymorphic
functions as in let port : port = int_t 0.
Opaque
ints
|
type 'a int_t
'a int_t has the same internal representation
as type int.val int_t : int -> 'a int_tval t_int : 'a int_t -> intval any_int : 'a int_t -> 'b int_tint_t, t_int and any_int are type conversion functions.val add : 'a int_t -> 'a int_t -> 'a int_tval sub : 'a int_t -> 'a int_t -> 'a int_tval mul : 'a int_t -> 'a int_t -> 'a int_tval div : 'a int_t -> 'a int_t -> 'a int_tval neg : 'a int_t -> 'a int_tadd, sub, mul, div and neg are the equivalents
of ( + ), ( - ), ( * ), ( / ) and ( ~- ).val successor : 'a int_t -> 'a int_tval predecessor : 'a int_t -> 'a int_tval increment : 'a int_t Pervasives.ref -> unitsuccessor, predecessor and increment are the equivalents
of ( + ), ( - ), ( * ), ( / ) and ( ~- ).val print_int_t : 'a int_t -> unit
Opaque
strings
|
type 'a string_t
'a string_t has the same internal representation
as type string.val string_t : string -> 'a string_tval t_string : 'a string_t -> stringval any_string : 'a string_t -> 'b string_tint_string, t_string and any_string are type conversion functions.val concat : 'a string_t -> 'a string_t -> 'a string_tval concat_list : string -> 'a string_t list -> 'a string_tconcat and concat_list are equivalents of ( ^ )
and String.concat.val print_string_t : 'a string_t -> unit