caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Esther Baruk <esther.baruk@gmail.com>
To: Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Section 7.14: First-class modules
Date: Tue, 14 Aug 2012 17:28:44 +0200	[thread overview]
Message-ID: <CAFzMiE0Y+BRDfvG3R5CJkVL4o46DsYbsk-k_Rsb5ODd_DTL4PQ@mail.gmail.com> (raw)
In-Reply-To: <502A6ABA.4070600@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2107 bytes --]

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
>
>

[-- Attachment #2: Type: text/html, Size: 3192 bytes --]

  reply	other threads:[~2012-08-14 15:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14 15:11 Matej Kosik
2012-08-14 15:28 ` Esther Baruk [this message]
2012-08-14 19:59   ` Matej Kosik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFzMiE0Y+BRDfvG3R5CJkVL4o46DsYbsk-k_Rsb5ODd_DTL4PQ@mail.gmail.com \
    --to=esther.baruk@gmail.com \
    --cc=5764c029b688c1c0d24a2e97cd764f@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).