Version française
Home     About     Download     Resources     Contact us    
Browse thread
Some questions about signatures
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: Some questions about signatures
> 1) Are OCaml's signatures opaque? I mean if they do hide the real
> implementation of data types and of non-declared values to the public, much
> like SML's :>

Yes, they are.  OCaml's ": SIG" construct behaves like ":> SIG" in
SML'97.

> 2) How can I extend a signature with new values and types? I've been
> using the 'include' directive, but I did not find it in the
> manual. Is this supposed to work or is it just a Caml-Light
> reminiscent.

No, it's an oversight in the manual.  "include" in signatures was
originally an experimental feature, but it seems useful enough that it
will stay.  I'll fix the manual.

> 3) What is the simplest way to build toplevel modules using
> functors? In SML everything on every file is bound to the toplevel
> environment and one can do just 'structure NewStruct =
> AFunctor(structure A = AParameter)' to get a brand new module. But
> in OCaml toplevel modules are defined in term of two files (mli/ml)
> so what are my options if I dont want to add a spurious path name?

Currently, you must put your functors inside toplevel structures,
which are then mapped to .ml/.mli files.  So, continuing your example
above, you have to write

        module NewStruct = ModA.Functor(AParameter)

or
        open ModA
        module NewStruct = Functor(AParameter)

One could imagine having compilation units that can be functors by
themselves.  It's mostly a problem of syntax: currently, the contents
of an implementation file (.ml) are systematically taken to be the
inside of a "module X = struct ... end" declaration;  extending this
to functors would require special syntax for the parameters.

Regards,

- Xavier Leroy