4

I'm using with sexp syntax to generate s-exp functions automagically.

The problem is data structures I'm printing with sexplib have some recursive pointers and printing will end up with stack overflow.

So I need to override a to_sexp function and make it just return "(SomeRecursiveData)", how can I do that ?

NOTE: My data definitions are in form:

type somedata ...
and someotherdata ...
and this_is_problematic_recursive_data
and ....
with sexp
sinan
  • 6,809
  • 6
  • 38
  • 67
  • 1
    Do you really need to have `this_is_problematic_recursive_data` in the same definition as the other types, or can it be defined before ? The idea would be to define it in a module `Foo` with type `t`, and `to_exp` defined in the same module. If it is not possible, you should probably use recursive modules. – Fabrice Le Fessant Jan 16 '13 at 10:54
  • @FabriceLeFessant I don't understand your solution(I'm new at OCaml), but I don't think modules can help. My problem is I have a list of refs and one of the refs point to the list itself at some point of run-time. I want to override that data type's(the one with list of refs) to_sexp to prevent this. – sinan Jan 16 '13 at 11:12

1 Answers1

1

I can't say that I fully understand your question but if function to_sexp is not cross recursive (i.e. let rec to_sexp = ... and not let rec to_sexp = ..... and foo = .... calls to_sexp somewhere.....) You can try this trick:

module A = struct type t with sexp end

module B = struct 
  include A
  let to_sexp = .... your code ...
end
Kakadu
  • 2,837
  • 19
  • 29