From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id D3CD87ED67 for ; Tue, 14 Aug 2012 17:29:05 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of esther.baruk@gmail.com) identity=pra; client-ip=209.85.212.180; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="esther.baruk@gmail.com"; x-sender="esther.baruk@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of esther.baruk@gmail.com designates 209.85.212.180 as permitted sender) identity=mailfrom; client-ip=209.85.212.180; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="esther.baruk@gmail.com"; x-sender="esther.baruk@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f180.google.com) identity=helo; client-ip=209.85.212.180; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="esther.baruk@gmail.com"; x-sender="postmaster@mail-wi0-f180.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlkCAHltKlDRVdS0k2dsb2JhbABEqF2IZgGISAgiAQEBAQkJCwkUBCOCIAEBAQMBEgITGQEbEgsBAwELBgULGiEhAQERAQUBChIGExIQh1sBAwYGC5lhCQOMI4JyhXgKGScDCleIcQEFDIoVZIYxA5N4gVOBFIl2gyk+hAA X-IronPort-AV: E=Sophos;i="4.77,766,1336341600"; d="scan'208";a="169877394" Received: from mail-wi0-f180.google.com ([209.85.212.180]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 14 Aug 2012 17:29:05 +0200 Received: by wibhm6 with SMTP id hm6so422223wib.9 for ; Tue, 14 Aug 2012 08:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=2CPzNCqp/A4ex/YUTm2dZjQHFFSfIodaz/j7HR84Klg=; b=wBSGkQGc3ng6UOlTB2WPMWGa4jtTW6xRQ/XT2c6I/ZwNsi01K7yH7V0LXDkSH0vU56 dPkYTlsiKyChUqxbhR7ZqJyEXhoRm4TNHZAagxXFSgFTFGixXcduklc5DaFxp3i73byR R0kKOiCfGnRqhZdR+FVCR75lqHUe0ayt0HsApMm1xRhT1G4fmj7nMcm4nMW3ITcD7UsX /u5oNweIrk5v/NZi5KpNI+6xBWfnVw3h/qEw6wMHzqSVykG2y9X153/ywC/3AHhQlMKP LuEXO0uyTNPjYdADLkwBK1QW2FESAaMPEH3C774a1xxuYn9o8jHqU/GSzj3FOyvVa7Jh Ntgw== Received: by 10.180.81.38 with SMTP id w6mr28733556wix.10.1344958145169; Tue, 14 Aug 2012 08:29:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.21.170 with HTTP; Tue, 14 Aug 2012 08:28:44 -0700 (PDT) In-Reply-To: <502A6ABA.4070600@gmail.com> References: <502A6ABA.4070600@gmail.com> From: Esther Baruk Date: Tue, 14 Aug 2012 17:28:44 +0200 Message-ID: To: Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com> Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=f46d044288c07b06e404c73b7866 Subject: Re: [Caml-list] Section 7.14: First-class modules --f46d044288c07b06e404c73b7866 Content-Type: text/plain; charset=ISO-8859-1 Hi, the type expression must be put between parenthesis. I think it is an error in the manual. The following works : (string, (module DEVICE)) Hashtbl.t Esther Baruk On Tue, Aug 14, 2012 at 5:11 PM, Matej Kosik < 5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote: > Hello, > > In Section 7.14 of the Ocaml manual: > > http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc81 > > there is a `Basic example'. > > The code (with some essential fillings) may look like this: > > -------------------------------------------------- > module type DEVICE = sig type t > val foo : unit -> unit > end > let devices : (string, module DEVICE) Hashtbl.t = Hashtbl.create 17 > > module SVG = struct > type t = int > let foo _ = assert false > end > > let _ = Hashtbl.add devices "SVG" (module SVG : DEVICE) > > module PDF = struct > type t = float > let foo _ = assert false > end > > let _ = Hashtbl.add devices "PDF" (module PDF: DEVICE) > > module Device = > (val (try Hashtbl.find devices (parse_cmdline()) > with Not_found -> eprintf "Unknown device %s\n"; exit 2) > : DEVICE > ) > --------------------------------------------------- > > When I try to compile this piece of code: > > ocamlc -o main main.ml > > I get an error: > > File "main.ml", line 4, characters 23-29: > Error: Syntax error > make: *** [main] Error 2 > > Is that example sound (for Ocaml 3.12)? > Or did I spoiled something myself? > I would be grateful for any advice. Thank you in advance. > > The compiler does not seem to like giving `module DEVICE' as the second > parameter to the Hashtbl.t type constructor. I am not actually sure what > `module DEVICE' could, semantically, mean. > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --f46d044288c07b06e404c73b7866 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

the type expression must be put between parenthesis.= I think it is an error in the manual.

The followi= ng works : (string, (module DEVICE)) Hashtbl.t


Esther Baruk


On Tue, Aug 14, 2012 at 5:11 PM, Matej K= osik <5764c029b688c1c0d24a2e97cd764f@gmail.com&= gt; wrote:
Hello,

In Section 7.14 of the Ocaml manual:

http://caml.inria.fr/pub/docs/manual-ocaml/manual021.htm= l#toc81

there is a `Basic example'.

The code (with some essential fillings) may look like this:

--------------------------------------------------
=A0 module type DEVICE =3D sig type t
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0val foo : unit ->= unit
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0end
=A0 let devices : (string, module DEVICE) Hashtbl.t =3D Hashtbl.create 17
=A0 module SVG =3D struct
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0type t =3D int
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0let foo _ =3D assert false
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0end

=A0 let _ =3D Hashtbl.add devices "SVG" (module SVG : DEVICE)

=A0 module PDF =3D struct
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0type t =3D float
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0let foo _ =3D assert false
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0end

=A0 let _ =3D Hashtbl.add devices "PDF" (module PDF: DEVICE)

=A0 module Device =3D
=A0 =A0 =A0 (val (try Hashtbl.find devices (parse_cmdline())
=A0 =A0 =A0 =A0 =A0 =A0 with Not_found -> eprintf "Unknown device %= s\n"; exit 2)
=A0 =A0 =A0 =A0: DEVICE
=A0 =A0 =A0 )
---------------------------------------------------

When I try to compile this piece of code:

=A0 =A0 ocamlc -o main main.ml=

I get an error:

=A0 =A0File "main.ml&= quot;, line 4, characters 23-29:
=A0 =A0Error: Syntax error
=A0 =A0make: *** [main] Error 2

Is that example sound (for Ocaml 3.12)?
Or did I spoiled something myself?
I would be grateful for any advice. Thank you in advance.

The compiler does not seem to like giving `module DEVICE' as the second=
parameter to the Hashtbl.t type constructor. I am not actually sure what
`module DEVICE' could, semantically, mean.

--
Caml-list mailing list. =A0Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--f46d044288c07b06e404c73b7866--