Re: Problem with information hiding.

"Gabriel Scherer [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <CAPFanBGR1T6=q=wBxGobu8wqMNJ_ux9X25DFL6JLGjC_TpPocw@mail.gmail.com>
Could you provide a self-contained piece of code that fails to compile? It
is easier to debug such problems when we see the error source, and when it
is possible to experiment (check that a fix suggestion work) before sending
a reply. Note that you don't need to make it minimal.

On Wed, Sep 30, 2015 at 7:51 PM, Hendrik Boom [email protected]
[ocaml_beginners] <[email protected]> wrote:

> My modules are hiding too much type information.
>
> I have a module that parses according to a grammar
> that is provided s a module parameter..
>
> The signature of the grammars involves several types
> relating to this grammar, such as the type of tokens
> produced by the lexer.
>
> module type GRAMMAR =
>   sig
>     type token
>     type gramon = {symbol : token; next : gramon option; alt : gramon
> option;}
>     type phrase
>     ...
>     ...
>   end;;
>
>
> And a parser, that uses this grammar description:
>
>
> module Mixfix(Grammar : GRAMMAR) =
>   struct
>     ...
>     ...
>     let rec read
>             (g : Grammar.gramon option)
>             (prio : int)
>             (input : Grammar.token Stream.t)
>             (psf : Grammar.phrase list)
>             (return : Grammar.phrase -> Grammar.token option ->
> Grammar.token Stream.t -> Grammar.phrase) =
>     ...
>     ...
>   end
>
> In general there can be a lot of different types
> that act as tokens.  But to test this parser, I define
> a specific grammar with token = char:
>
>
> module Chargram : GRAMMAR with token = char =
>   struct
>     type token = char;; (* Should really be a module's type parameter *)
>     ...
>     ...
>   end;;
>
>
> and set up a test parser by giving Mixfix this grammar:
>
>
> module Test = Mixfix(Chargram);;
>
>
> Now this doesn't work because of information-hiding.
> Test.token is an abstract type.  Even though in this
> case it *is* char, that information is not available
> when I call Test's functions outside the module, so
> the type check fails when I try to call Test.read with
> a char stream.
>
>
> So what is the *correct* way of providing this parametrization,
> so after specializing the module to char, I can call
> its functions knowing that Test.token is char, and the type check
> will succeed?
>
> Or should I be using some entirely different mechanism to
> accomplish my purpose?
>
> -- hendrik
>
>
>
>
>
>
> ------------------------------------
> Posted by: Hendrik Boom <[email protected]>
> ------------------------------------
>
> Archives up to December 31, 2011 are also downloadable at
> http://www.connettivo.net/cntprojects/ocaml_beginners
> The archives of the very official ocaml list (the seniors' one) can be
> found at http://caml.inria.fr
> Attachments are banned and you're asked to be polite, avoid flames etc.
> ------------------------------------
>
> Yahoo Groups Links
>
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.