In a.ml, the type of record t is determined and also defined transparently in a.mli, that is, in the d-interface, so that the type definition is available to all other files.
a.ml also has a func function that returns a list of t.
Now in another file, b.ml, I m calls func, now, obviously, the ocaml wud nt compiler can output d types of objects stored in the d-list, for the compiler it's just a list. so in b.ml i have something like dis
let tlist = A.func in
let vart = List.hd tlist in
printf "%s\n" vart.name (*name is a field in record t*)
Now here I get a sayin compiler error "Invalid label field record name", which makes sense since the compiler cannot output d of type vart.
my first question is: how can I explicitly specify d of type vart as t Here? I tried to do "let vart: At =" but got the same error.
I also tried creating another function to retrieve the first element of the d list and specifying the return type as At, but then I got the "Unbound value of At". I have done this:
let firstt = function
[] -> 0
| x :: _ -> A.t x ;;
The problem is that the compiler cannot recognize At (type) in b.ml but is able to recognize the A.func function. If I remove At from b.ml, I do not make compiler errors.
focus source
share