Page
Library
Module
Module type
Parameter
Class
Class type
Source
Owee_marker
SourceA 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
*)Possible outcomes for the execution of a service
User API to work with marked objects.
Type of object marked with the safe interface
Query an object for a service
User API to work with graph of marked objects.
Type storing the state needed of traversal of marked OCaml object graphs
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.
The signature that needs to be implemented to add service support to your objects.