From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA02667; Sat, 23 Oct 2004 13:41:50 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 NAA02311 for ; Sat, 23 Oct 2004 13:41:49 +0200 (MET DST) 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 i9NBfm4q009340 for ; Sat, 23 Oct 2004 13:41:49 +0200 Received: from rich by annexia.force9.co.uk with local (Exim 3.36 #1 (Debian)) id 1CLKHM-0005G0-00 for ; Sat, 23 Oct 2004 12:41:48 +0100 Date: Sat, 23 Oct 2004 12:41:48 +0100 To: caml-list@inria.fr Subject: Re: [Caml-list] Polymorphism and the "for" loop Message-ID: <20041023114148.GA20016@annexia.org> References: <200410211950.43396.jon@jdh30.plus.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="jI8keyz6grp/JLjh" Content-Disposition: inline In-Reply-To: <200410211950.43396.jon@jdh30.plus.com> User-Agent: Mutt/1.5.5.1+cvs20040105i From: Richard Jones X-Miltered: at concorde with ID 417A437C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 hash:01 ignoring:01 val:01 val:01 endline:01 endline:01 ltd:98 match:02 unit:03 unit:03 let:04 let:04 investment:94 polymorphism:06 X-Attachments: type="application/pgp-signature" name="signature.asc" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --jI8keyz6grp/JLjh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable I've got a problem which is sort of related to this discussion. I want to store a function which has type unit -> 'a (which is to say, I want to store a function which could return any type) in a hash table. Later, I want to call this function, ignoring the return type. A diluted example, with my notes added: # let f =3D ref None;; val f : '_a option ref =3D {contents =3D None} # let store_f f' =3D f :=3D Some f';; val store_f : '_a -> unit =3D (I want store_f to have type (unit -> 'a) -> unit.) # let do_f () =3D match !f with | None -> print_endline "no function" | Some f -> ignore (f ());; val do_f : unit -> unit =3D # store_f;; - : (unit -> '_a) -> unit =3D (Almost ...) # store_f (fun () -> print_endline "this is the stored function");; - : unit =3D () # do_f ();; this is the stored function - : unit =3D () # store_f;; - : (unit -> unit) -> unit =3D I also tried replacing the definition of store_f with: # let store_f (f' : unit -> 'a) =3D f :=3D Some f';; val store_f : (unit -> '_a) -> unit =3D Is this possible? 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 http://youunlimited.co.uk/ - Personal improvement courses --jI8keyz6grp/JLjh 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) iD8DBQFBekN84le1M6q9pzoRAoHwAKDTksSsEEQpI9twVWYgnihgULpc5gCg4hOQ t8qaajQlyJrv3kszsye4xuU= =CHt1 -----END PGP SIGNATURE----- --jI8keyz6grp/JLjh-- ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners