I am curious to understand why this error occurs, and this is the best way to get around it.
I have several types.ml and types.mli files that determine the type of the value variant, which can have many different built-in OCaml types (float, int, list, map, set, etc.).
Since I should use std-lib over this option, I needed to instantiate the Set module through a functor in order to be able to use sets of type value , defining the ValueSet module.
The final .ml file looks something like this:
module rec I : sig type value = Nil | Int of int | Float of float | Complex of Complex.t | String of string | List of (value list) ref | Array of value array | Map of (value, value) Hashtbl.t | Set of ValueSet.t ref | Stack of value Stack.t ... type t = value val compare : t -> t -> int end = struct (* same variant type *) and string_value v = match v with (* other cases *) | Set l -> sprintf "{%s} : set" (ValueSet.fold (fun iv -> v^(string_value i)^" ") !l "") end and OrderedValue : sig type t = I.value val compare : t -> t -> int end = struct type t = I.value let compare = Pervasives.compare end and ValueSet : Set.S with type elt = I.value = Set.Make(I)
As you can see, I needed to define a ValueSet module from a functor in order to be able to use this data type. The problem occurs when I want to use this module inside declaration I So I get the following error:
Error: cannot safely evaluate the definition of a recursively-defined module I
Why is this happening? Is this a good way to solve this problem? And just know my approach to what I'm trying to do right? In addition, it works as intended (I can use the ValueSet type with my operations in other modules, but I have to comment on the involved string in types.ml in order to pass the compilation phase).
I tried to remove all the excess code and reduce the code to the necessary to investigate this error .. if this is not enough, just ask :)
EDIT: according to the OCaml link, we have that
Currently, the compiler requires that all dependency cycles between recursively defined module identifiers go through at least one “safe” module. A module is “safe” if all the definitions of values contained in it have function types typexpr1 → typexpr2.
That is all I have found so far, but I do not understand the exact meaning.
thanks in advance