Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Ques from a beginner: how to access a type defined in one .ml file in another .ml file
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-05-12 (10:30)
From: Tarun Sethi <tarunsethi01@g...>
Subject: Ques from a beginner: how to access a type defined in one .ml file in another .ml file

I m very new to ocaml and I am not sure if this the right forum to ask a
beginner level question. I have tried reading tutorials and the manual but
no help. Please help me on the problem below,

In a record type t is defined and is also defined transparently
in a.mli, i.e. in d interface so that the type definition is available
to all other files. also has a function, func, which returns a list of t.

Now in another file,  i m calling func, now obviously ocaml
compiler wud nt be able to infer d type of objects stored in d list,
for compiler its just a list. so in, i hav something like dis,

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

Now here i get a compiler error sayin "Unbound record field label
name" which makes sense as compiler can't infer d type of vart.

my first question: how do I explicitly provide d type of vart as t
                         i tried doing "let vart:A.t =  " but got the
same error.

I also tried creating another function to fetch the first element of d
list and mentioning return type as A.t, but then i got the "Unbound
value A.t". I did this:

let firstt = function
     [] -> 0
   | x :: _ -> A.t x ;;

The problem is compiler is unable to recognize A.t (a type) in
but is able to recognize function A.func. If I remove A.t from the, i don'get any compiler errors.

Please help, its urgent work.
Thanks in advance!