Problem with information hiding.

"Hendrik Boom [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
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
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.