From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id C7D69BC57 for ; Wed, 12 May 2010 12:30:27 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmkCAMsf6kvRVaC2mGdsb2JhbACRZow5CBUBAQEBAQgJDAcRIqkgggCFQi6ITgEBAwWCY4IqBA X-IronPort-AV: E=Sophos;i="4.53,213,1272837600"; d="scan'208";a="62740218" Received: from mail-gy0-f182.google.com ([209.85.160.182]) by mail4-smtp-sop.national.inria.fr with ESMTP; 12 May 2010 12:30:26 +0200 Received: by gyh20 with SMTP id 20so3316469gyh.27 for ; Wed, 12 May 2010 03:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=0hKGLcQOQub+Kj0A6nZwy+ySDSUxl2nlyXfnI7c9eEQ=; b=PYYwBTngnrPuizwU3yIEReww6sim5xeYN49C2CVkvXJm1H5bT/pI1DkmkVoar6Yyhj L5zsPdtKUswfdRULKdbn7LmmLoWU0W8io+j6A+79FWBynXtqAkNMOLwb0jkJH/vsEujK zXDfpFc0sbJmIPXYVEe8S8ul8l7C85oS5ozg4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=IXiWpng3x4r6ey+xL8xx4lrAMo+YgR62MWLlhc3PzWeMWSd9o0xAtEAXmYTsxgNzMF CseLJcqz5U+FCU8963atg3Oi7ALDfgg6iA1qtS/T49TUX5rOcfNEkqWz8zULizOvd+cH r0ZM2jnxbzK/olJaB8nxl4JcX+QpYvM7zRd2w= MIME-Version: 1.0 Received: by 10.150.62.14 with SMTP id k14mr12087120yba.35.1273660224532; Wed, 12 May 2010 03:30:24 -0700 (PDT) Received: by 10.150.51.9 with HTTP; Wed, 12 May 2010 03:30:24 -0700 (PDT) Date: Wed, 12 May 2010 06:30:24 -0400 Message-ID: Subject: Ques from a beginner: how to access a type defined in one .ml file in another .ml file From: Tarun Sethi To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=000e0cd4c3083f6f7e048663213e X-Spam: no; 0.00; ocaml:01 mli:01 ocaml:01 compiler:01 compiler:01 printf:01 mli:01 printf:01 unbound:01 unbound:01 func:01 func:01 explicitly:02 explicitly:02 defined:02 --000e0cd4c3083f6f7e048663213e Content-Type: text/plain; charset=ISO-8859-1 Hi, 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.ml 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. a.ml also has a function, func, which returns a list of t. Now in another file, b.ml 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 b.ml, i hav 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 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 here? 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 b.ml but is able to recognize function A.func. If I remove A.t from the b.ml, i don'get any compiler errors. Please help, its urgent work. Thanks in advance! ~Tarun --000e0cd4c3083f6f7e048663213e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,

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

In a.ml a record type t is de= fined and is also defined transparently
in a.mli, i.e. in d interface so that the type definition is available
to all other files.

a.ml also has a function, fun= c, which returns a list of t.

Now in another file, b.ml =A0= 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 b.ml, i hav something like dis,

let tlist =3D A.func in
let vart =3D List.hd tlist in
printf "%s\n" vart= .name =A0 =A0 (*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
here?
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0i tried doing "let= vart:A.t =3D =A0" 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 =3D function
=A0 =A0 =A0[] -> 0
=A0 =A0| x :: _ -> A.t x ;;

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

Please help, its urgent work.
Thanks in advance!

~Tarun





--000e0cd4c3083f6f7e048663213e--