jon.recoil.org

Source file stringable.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(** Provides type-specific conversion functions to and from [string]. *)

open! Import

(** Templated to provide two [of_string] functions. The first may stack allocate, and
    always takes its input at the same mode as its output. The second may take local
    input, and always produces global output. In the default case of global input and heap
    output, they are equivalent and one shadows the other. *)
module type%template
  [@mode l = (local, global)] [@alloc a @ m = (heap_global, stack_local)] To_stringable = sig
  type t

  val to_string : t @ m -> string @ m [@@alloc a]
  val to_string : t @ l -> string
end

module type%template [@mode l = (local, global)] Of_stringable = sig
  type t

  val of_string : string @ l -> t
end

module type%template [@mode l = (local, global)] [@alloc a = (stack, heap)] S = sig
  type t

  include Of_stringable [@mode l] with type t := t
  include To_stringable [@mode l] [@alloc a] with type t := t
end