Source

ocaml-llvm-phantom / lib / phantom.mli

Full commit
(**
   Opening this module is NOT recommended. 
   Instead, open Phantom.Open. Using a module alias is also helpful:
   
   module P = Phantom
   open P.Open
*)
type ('phantom, 'cont) t

module Open : sig
  type unknown 
  val unknown : unknown

  val (!<) : ('a, 'cont) t -> 'cont
  (** Forget the phantom *)

  val (!>) : 'cont -> (unknown, 'cont) t
  (** Safe lift up with the unknown phantom *)

  val (!?) : ('a, 'cont) t -> (unknown, 'cont) t
  (** Forget the phantom *)
end

type unknown = Open.unknown
val unknown : Open.unknown
val (!<) : ('a, 'cont) t -> 'cont
val (!>) : 'cont -> (unknown, 'cont) t
val (!?) : ('a, 'cont) t -> (unknown, 'cont) t

val unsafe : 'cont -> ('unsafe, 'cont) t
(** [unsafe v] lifts up [v] with an arbitrary phantom. Use with care. *)

val magic : ('a, 'cont) t -> ('unsafe, 'cont) t
(** [magic v] changes the phantom ov [v]. Use with care. *)

val map : ('cont -> 'cont2) -> ('a, 'cont) t -> ('a, 'cont2) t
val combine : 'tag -> ('a, 'cont) t -> ('a, 'tag * 'cont) t

type ('phantoms, 'cont) ts
(** phantom heterogeneous 'cont list *)

module List : sig
  val unsafe_list : 'cont list -> ('unsafe, 'cont) ts
  (** [unsafe_list ls] lifts up [ls] with arbitrary phantoms. Use with care. *)
  val to_list : ('a, 'cont) ts -> 'cont list
  val to_unknown_list : ('a, 'cont) ts -> (unknown, 'cont) t list
  val to_array : ('a, 'cont) ts -> 'cont array
  val to_unknown_array : ('a, 'cont) ts -> (unknown, 'cont) t array
  val of_unknown_list : (unknown, 'cont) t list -> (unknown, 'cont) ts
  val of_unknown_array : (unknown, 'cont) t array -> (unknown, 'cont) ts
  val unsafe_of_list : 'cont list -> ('unsafe, 'cont) ts
  val unsafe_of_array : 'cont array -> ('unsafe, 'cont) ts
  
  val length : ('a, 'cont) ts -> int
  val map : ('cont -> 'cont2) -> ('a, 'cont) ts -> ('a, 'cont2) ts
  val combine : 'tag list -> ('a, 'cont) ts -> ('a, ('tag * 'cont)) ts

  type ('phantoms, 'cont) t = ('phantoms, 'cont) ts
end

(* This encoding is correct only if the parameter cannot be the unit or a tuple *)
type tpl0 = unit
type 'a0 tpl1 = ('a0 * unit)
type ('a0,'a1) tpl2 = ('a0 * ('a1 * unit))
type ('a0,'a1,'a2) tpl3 = ('a0 * ('a1 * ('a2 * unit)))
type ('a0,'a1,'a2,'a3) tpl4 = ('a0 * ('a1 * ('a2 * ('a3 * unit))))
type ('a0,'a1,'a2,'a3,'a4) tpl5 = ('a0 * ('a1 * ('a2 * ('a3 * ('a4 * unit)))))
type ('a0,'a1,'a2,'a3,'a4,'a5) tpl6 = ('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * unit))))))
type ('a0,'a1,'a2,'a3,'a4,'a5,'a6) tpl7 = ('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * ('a6 * unit)))))))
type ('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7) tpl8 = ('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * ('a6 * ('a7 * unit))))))))
type ('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7,'a8) tpl9 = ('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * ('a6 * ('a7 * ('a8 * unit)))))))))
type ('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7,'a8,'a9) tpl10 = ('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * ('a6 * ('a7 * ('a8 * ('a9 * unit))))))))))

(** {6 Construction of phantom hetero list} *)

val c0 : (tpl0,'c) ts
val c1 : ('a0,'c) t -> ('a0 tpl1,'c) ts
val c2 : ('a0,'c) t -> ('a1,'c) t -> (('a0,'a1) tpl2,'c) ts
val c3 : ('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> (('a0,'a1,'a2) tpl3,'c) ts
val c4 : ('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> (('a0,'a1,'a2,'a3) tpl4,'c) ts
val c5 : ('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> (('a0,'a1,'a2,'a3,'a4) tpl5,'c) ts
val c6 : ('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> (('a0,'a1,'a2,'a3,'a4,'a5) tpl6,'c) ts
val c7 : ('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> (('a0,'a1,'a2,'a3,'a4,'a5,'a6) tpl7,'c) ts
val c8 : ('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> ('a7,'c) t -> (('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7) tpl8,'c) ts
val c9 : ('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> ('a7,'c) t -> ('a8,'c) t -> (('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7,'a8) tpl9,'c) ts
val c10 : ('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> ('a7,'c) t -> ('a8,'c) t -> ('a9,'c) t -> (('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7,'a8,'a9) tpl10,'c) ts

(** {6 Deconstruction of phantom hetero list} *)

val d0 : (tpl0,'c) ts -> unit
val d1 : ('a0 tpl1,'c) ts -> ('a0,'c) t
val d2 : (('a0,'a1) tpl2,'c) ts -> ('a0,'c) t * ('a1,'c) t
val d3 : (('a0,'a1,'a2) tpl3,'c) ts -> ('a0,'c) t * ('a1,'c) t * ('a2,'c) t
val d4 : (('a0,'a1,'a2,'a3) tpl4,'c) ts -> ('a0,'c) t * ('a1,'c) t * ('a2,'c) t * ('a3,'c) t
val d5 : (('a0,'a1,'a2,'a3,'a4) tpl5,'c) ts -> ('a0,'c) t * ('a1,'c) t * ('a2,'c) t * ('a3,'c) t * ('a4,'c) t
val d6 : (('a0,'a1,'a2,'a3,'a4,'a5) tpl6,'c) ts -> ('a0,'c) t * ('a1,'c) t * ('a2,'c) t * ('a3,'c) t * ('a4,'c) t * ('a5,'c) t
val d7 : (('a0,'a1,'a2,'a3,'a4,'a5,'a6) tpl7,'c) ts -> ('a0,'c) t * ('a1,'c) t * ('a2,'c) t * ('a3,'c) t * ('a4,'c) t * ('a5,'c) t * ('a6,'c) t
val d8 : (('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7) tpl8,'c) ts -> ('a0,'c) t * ('a1,'c) t * ('a2,'c) t * ('a3,'c) t * ('a4,'c) t * ('a5,'c) t * ('a6,'c) t * ('a7,'c) t
val d9 : (('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7,'a8) tpl9,'c) ts -> ('a0,'c) t * ('a1,'c) t * ('a2,'c) t * ('a3,'c) t * ('a4,'c) t * ('a5,'c) t * ('a6,'c) t * ('a7,'c) t * ('a8,'c) t
val d10 : (('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7,'a8,'a9) tpl10,'c) ts -> ('a0,'c) t * ('a1,'c) t * ('a2,'c) t * ('a3,'c) t * ('a4,'c) t * ('a5,'c) t * ('a6,'c) t * ('a7,'c) t * ('a8,'c) t * ('a9,'c) t

val get0 : (('a0 * _),'c) ts -> ('a0,'c) t
val get1 : (('a0 * ('a1 * _)),'c) ts -> ('a1,'c) t
val get2 : (('a0 * ('a1 * ('a2 * _))),'c) ts -> ('a2,'c) t
val get3 : (('a0 * ('a1 * ('a2 * ('a3 * _)))),'c) ts -> ('a3,'c) t
val get4 : (('a0 * ('a1 * ('a2 * ('a3 * ('a4 * _))))),'c) ts -> ('a4,'c) t
val get5 : (('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * _)))))),'c) ts -> ('a5,'c) t
val get6 : (('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * ('a6 * _))))))),'c) ts -> ('a6,'c) t
val get7 : (('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * ('a6 * ('a7 * _)))))))),'c) ts -> ('a7,'c) t
val get8 : (('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * ('a6 * ('a7 * ('a8 * _))))))))),'c) ts -> ('a8,'c) t
val get9 : (('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * ('a6 * ('a7 * ('a8 * ('a9 * _)))))))))),'c) ts -> ('a9,'c) t
val get10 : (('a0 * ('a1 * ('a2 * ('a3 * ('a4 * ('a5 * ('a6 * ('a7 * ('a8 * ('a9 * ('a10 * _))))))))))),'c) ts -> ('a10,'c) t

(** {6 Uncurry} *)

val uncurry0 : (unit -> 'z) -> ((tpl0, 'c) ts -> 'z)
val uncurry1 : (('a0,'c) t -> 'z) -> (('a0 tpl1, 'c) ts -> 'z)
val uncurry2 : (('a0,'c) t -> ('a1,'c) t -> 'z) -> ((('a0,'a1) tpl2, 'c) ts -> 'z)
val uncurry3 : (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> 'z) -> ((('a0,'a1,'a2) tpl3, 'c) ts -> 'z)
val uncurry4 : (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> 'z) -> ((('a0,'a1,'a2,'a3) tpl4, 'c) ts -> 'z)
val uncurry5 : (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> 'z) -> ((('a0,'a1,'a2,'a3,'a4) tpl5, 'c) ts -> 'z)
val uncurry6 : (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> 'z) -> ((('a0,'a1,'a2,'a3,'a4,'a5) tpl6, 'c) ts -> 'z)
val uncurry7 : (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> 'z) -> ((('a0,'a1,'a2,'a3,'a4,'a5,'a6) tpl7, 'c) ts -> 'z)
val uncurry8 : (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> ('a7,'c) t -> 'z) -> ((('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7) tpl8, 'c) ts -> 'z)
val uncurry9 : (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> ('a7,'c) t -> ('a8,'c) t -> 'z) -> ((('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7,'a8) tpl9, 'c) ts -> 'z)
val uncurry10 : (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> ('a7,'c) t -> ('a8,'c) t -> ('a9,'c) t -> 'z) -> ((('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7,'a8,'a9) tpl10, 'c) ts -> 'z)

(** {6 Curry} *)

val curry0 : ((tpl0,'c) ts -> 'z) -> unit -> 'z
val curry1 : (('a0 tpl1,'c) ts -> 'z) -> (('a0,'c) t -> 'z)
val curry2 : ((('a0,'a1) tpl2,'c) ts -> 'z) -> (('a0,'c) t -> ('a1,'c) t -> 'z)
val curry3 : ((('a0,'a1,'a2) tpl3,'c) ts -> 'z) -> (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> 'z)
val curry4 : ((('a0,'a1,'a2,'a3) tpl4,'c) ts -> 'z) -> (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> 'z)
val curry5 : ((('a0,'a1,'a2,'a3,'a4) tpl5,'c) ts -> 'z) -> (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> 'z)
val curry6 : ((('a0,'a1,'a2,'a3,'a4,'a5) tpl6,'c) ts -> 'z) -> (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> 'z)
val curry7 : ((('a0,'a1,'a2,'a3,'a4,'a5,'a6) tpl7,'c) ts -> 'z) -> (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> 'z)
val curry8 : ((('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7) tpl8,'c) ts -> 'z) -> (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> ('a7,'c) t -> 'z)
val curry9 : ((('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7,'a8) tpl9,'c) ts -> 'z) -> (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> ('a7,'c) t -> ('a8,'c) t -> 'z)
val curry10 : ((('a0,'a1,'a2,'a3,'a4,'a5,'a6,'a7,'a8,'a9) tpl10,'c) ts -> 'z) -> (('a0,'c) t -> ('a1,'c) t -> ('a2,'c) t -> ('a3,'c) t -> ('a4,'c) t -> ('a5,'c) t -> ('a6,'c) t -> ('a7,'c) t -> ('a8,'c) t -> ('a9,'c) t -> 'z)