From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 7FC66BC28 for ; Fri, 12 Nov 2004 17:37:53 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iACGbq9Y024384 for ; Fri, 12 Nov 2004 17:37:53 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA31351 for ; Fri, 12 Nov 2004 17:37:52 +0100 (MET) Received: from annexia.force9.co.uk (annexia.force9.co.uk [212.56.101.183]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iACGbpIZ028228 for ; Fri, 12 Nov 2004 17:37:52 +0100 Received: from rich by annexia.force9.co.uk with local (Exim 3.36 #1 (Debian)) id 1CSeQc-0003f8-00; Fri, 12 Nov 2004 16:37:38 +0000 Date: Fri, 12 Nov 2004 16:37:38 +0000 To: josh Cc: caml-list@inria.fr Subject: Re: [Caml-list] Specifying abstract type in a record Message-ID: <20041112163738.GA14038@annexia.org> References: <20041111083547.GA13116@pulp.anu.edu.au> <1100163369.2579.70.camel@pelican.wigram> <20041111090931.GA13972@pulp.anu.edu.au> <20041111104849.29e7e506@mpiat2314> <4194E0C7.4060102@trdlnk.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="0F1p//8PRICkK4MW" Content-Disposition: inline In-Reply-To: <4194E0C7.4060102@trdlnk.com> User-Agent: Mutt/1.5.5.1+cvs20040105i From: Richard Jones X-Miltered: at nez-perce with ID 4194E6E0.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4194E6DF.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 val:01 val:01 redefined:01 beginner's:01 beginner's:01 ocaml:01 beginners:01 libs:01 ocaml:01 t'':98 t'':98 goodbye:98 goodbye:98 X-Attachments: type="application/pgp-signature" name="signature.asc" X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: --0F1p//8PRICkK4MW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Nov 12, 2004 at 10:11:51AM -0600, josh wrote: > OK, Here's what I'm trying to do: >=20 > # type doer =3D { file_name:string ; actor: ('a -> unit) };; >=20 > But when I do this, it tells me that I've got "Unbound type parameter 'a = ". You need to do this: # type 'a doer =3D { file_name:string ; actor: ('a -> unit) };; type 'a doer =3D { file_name : string; actor : 'a -> unit; } because you're creating a polymorphic type ('a doer). Note that this won't let you store an actor function of type, say, int -> unit and then replace it with another function of type, say, string -> unit. For the same reason it won't let you pass an ``int doer'' to a function expecting a ``string doer''. > # type t > # type doer =3D { file_name:string; actor (t -> unit) };; >=20 > It works until I try to use a created record: >=20 > # let b =3D {file_name =3D "one"; actor =3D (fun x -> () ) };; > # b.actor 10;; > The expression has type int but is used with type t >=20 > even if I try to do this >=20 > # type t =3D int;; >=20 > it doesn't work. OK, this is another problem. Here what you're doing is defining a _new_ type ``t'', which is unrelated to your old type ``t''. Here's another example: # let f () =3D "hello";; val f : unit -> string =3D # f ();; - : string =3D "hello" # let g =3D f;; =20 val g : unit -> string =3D # let f () =3D "goodbye";; val f : unit -> string =3D # f ();; - : string =3D "goodbye" # g ();; - : string =3D "hello" Notice that ``g'' still calls the old ``f'', even after ``f'' has been redefined. There's a beginner's list: > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Rich. --=20 Richard Jones. http://www.annexia.org/ http://www.j-london.com/ >>> http://www.team-notepad.com/ - collaboration tools for teams <<< Merjis Ltd. http://www.merjis.com/ - improving website return on investment Use Perl libs in OCaml - http://www.merjis.com/developers/perl4caml --0F1p//8PRICkK4MW Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFBlObS4le1M6q9pzoRAp/PAKDU5kP3NlXjl7eOJnjvONlmApHceQCeKY4T s7P8w+Zn9gV1lWN8QOF0X6k= =GC41 -----END PGP SIGNATURE----- --0F1p//8PRICkK4MW--