Library
Module
Module type
Parameter
Class
Class type
A module to manually instrument values and implement dynamic services based on the actual type of these values.
The idea is to put a distinguished word, of type t marker
in a value of type t
. This module implements tools to generate and scan for such word, and execute functions based on the type recovered.
Manipulation of markers should be done with care: if the introspection find any value with the t marker
word, it will incorrectly behave as if value was of type t
.
The Safe_ functors ease manipulation of markers, at the cost of wrapping values. Use the Unsafe_ ones if you know what you are doing.
Services are typed queries which can be executed on arbitrary ocaml objects. The query will succeed if:
The extensible type of dynamic services. Add your own services to the list and run queries at runtime without knowledge of the object type.
Think of this as an extensible list of methods (and of markers as a vtable for those methods).
type service +=
| Name : string service
A user-friendly label for your object / class of objects
*)| Traverse : ((Obj.t -> 'acc -> 'acc) -> 'acc -> 'acc) service
Run a fold functions on object leafs, useful to traverse structure which are partially opaque.
*)| Locate : Owee_location.t list service
Return a list of locations relevant to the object
*)User API to work with marked objects.
val get : 'a marked -> 'a
val query_service : 'a -> 'result service -> 'result service_result
Query an object for a service
User API to work with graph of marked objects.
val start_cycle : unit -> cycle
Start a fresh cycle detector
val end_cycle : cycle -> unit
Release all ressources associated to the cycle. The cycle value should not be used after that.
Mark an object as seen in a cycle. An integer uniquely identifying the object in this cycle is returned.
Was the object already seen during this traversal? If seen, the integer resulting from the call to mark_seen
is returned.
Generate a fresh name, guaranteed not to collide with results of mark_seen
.
Implementor API.
module type T0 = sig ... end
The signature that needs to be implemented to add service support to your objects.
module type T1 = sig ... end
module type T2 = sig ... end
module type T3 = sig ... end