How to access a type defined in one. XML file in another .ml file

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.

+5
source share
2 answers

Compiler able to recognize A.tto indicate the type tof file a.ml.

, t x, t - , x . . t , a.ml. , , .

, :

  • OCaml. , ( , , ) , , , , . , , ( , , ) .

  • b.ml f r A.t, r.A.f.

+7
let tlist = A.func in
let vart = List.hd tlist in
printf "%s\n" vart.name     (*name is a field in record t*)

tlist - , , 'a -> A.t list, List.hd let vart = List.hd tlist.

, A.t, let tlist = A.func (your_argument-s-_here), , , .

0

All Articles