* [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
* Re: [Caml-list] Section 7.14: First-class modules
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
0 siblings, 1 reply; 3+ messages in thread
From: Esther Baruk @ 2012-08-14 15:28 UTC (permalink / raw)
To: Matej Kosik; +Cc: caml-list
[-- 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Section 7.14: First-class modules
2012-08-14 15:28 ` Esther Baruk
@ 2012-08-14 19:59 ` Matej Kosik
0 siblings, 0 replies; 3+ messages in thread
From: Matej Kosik @ 2012-08-14 19:59 UTC (permalink / raw)
To: Esther Baruk; +Cc: caml-list
On 14/08/12 16:28, Esther Baruk wrote:
> 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
I have filed a bugreport concerning the documentation.
Besides missing parentheses, there were no other problems. I never
needed this feature before but the refactoring I made today would be
impossible without it.
Thanks again :-)
^ 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