caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Section 7.14: First-class modules
@ 2012-08-14 15:11 Matej Kosik
  2012-08-14 15:28 ` Esther Baruk
  0 siblings, 1 reply; 3+ messages in thread
From: Matej Kosik @ 2012-08-14 15:11 UTC (permalink / raw)
  To: caml-list

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-08-14 19:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-14 15:11 [Caml-list] Section 7.14: First-class modules Matej Kosik
2012-08-14 15:28 ` Esther Baruk
2012-08-14 19:59   ` Matej Kosik

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