caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Declaring a parameterized type in a .mli
@ 2013-04-08  3:17 William Smith
  2013-04-08  3:57 ` Ivan Gotovchits
  0 siblings, 1 reply; 4+ messages in thread
From: William Smith @ 2013-04-08  3:17 UTC (permalink / raw)
  To: Caml-list

Hi

I'm trying to create a generic ID module so that it is easy to make 
multiple distinct ID classes.   I want to be able to create sets and 
maps of them so I've made my signature compatible with Set.Make but I'm 
not making it that far yet.  I want to have one class of IDs for NFA 
states and another for DFA states etc. and I want to reuse the code when 
I find I need other ID classes.

Here's what I've got in my .mli:

module IDRoot :
sig
end

module GenericID ( Root : sig end ) :
sig
     type t
     val compare : t -> t -> int
     val to_string : t -> string
     val cons : unit -> t
end

module Id = GenericID( IDRoot )

I get a syntax error even though I think I am following the reference 
books online.  The error is on the equal sign of the last line:

File "broken.mli", line 13, characters 10-11:
Error: Syntax error

(For each class of IDs I will declare another IDRoot but with a 
different name.)   Is there a better way?  This one seems really simple 
if I could correct the syntax error.

Thanks for any help you can offer.

Bill Smith

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

* Re: [Caml-list] Declaring a parameterized type in a .mli
  2013-04-08  3:17 [Caml-list] Declaring a parameterized type in a .mli William Smith
@ 2013-04-08  3:57 ` Ivan Gotovchits
  2013-04-08  4:05   ` Markus Mottl
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Gotovchits @ 2013-04-08  3:57 UTC (permalink / raw)
  To: William Smith; +Cc: Caml-list

William Smith <bills@emu-bark.com> writes:


> module Id = GenericID( IDRoot )
Compiler is right =) You can't do this in a module type specification. 

Though you can define a signature of your module in some *.ml file and
use it later in your module type declaration.

For example:

<file sig.ml>:
   module type Id = sig
       type t
       val compare : t -> t -> int
       val to_string : t -> string
       val cons : unit -> t
   end

   module type Root = sig ... end



<file  genericId.mli>
   open Sig
   module Make(Root:Root): Id

   module DefaultId : Id
   
-- 
         (__) 
         (oo) 
   /------\/ 
  / |    ||   
 *  /\---/\ 
    ~~   ~~   
...."Have you mooed today?"...

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

* Re: [Caml-list] Declaring a parameterized type in a .mli
  2013-04-08  3:57 ` Ivan Gotovchits
@ 2013-04-08  4:05   ` Markus Mottl
  2013-04-08  4:09     ` Ivan Gotovchits
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Mottl @ 2013-04-08  4:05 UTC (permalink / raw)
  To: Ivan Gotovchits; +Cc: William Smith, Caml-list

On Sun, Apr 7, 2013 at 11:57 PM, Ivan Gotovchits <ivg@ieee.org> wrote:
> > module Id = GenericID( IDRoot )
> Compiler is right =) You can't do this in a module type specification.

Note, however, that this will work:

  module Id : module type of GenericID (IDRoot)

Regards,
Markus

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

* Re: [Caml-list] Declaring a parameterized type in a .mli
  2013-04-08  4:05   ` Markus Mottl
@ 2013-04-08  4:09     ` Ivan Gotovchits
  0 siblings, 0 replies; 4+ messages in thread
From: Ivan Gotovchits @ 2013-04-08  4:09 UTC (permalink / raw)
  To: Markus Mottl; +Cc: William Smith, Caml-list

Markus Mottl <markus.mottl@gmail.com> writes:

> On Sun, Apr 7, 2013 at 11:57 PM, Ivan Gotovchits <ivg@ieee.org> wrote:
>> > module Id = GenericID( IDRoot )
>> Compiler is right =) You can't do this in a module type specification.
>
> Note, however, that this will work:
>
>   module Id : module type of GenericID (IDRoot)
>
> Regards,
> Markus

Absolutely... but only since 3.12.

-- 
         (__) 
         (oo) 
   /------\/ 
  / |    ||   
 *  /\---/\ 
    ~~   ~~   
...."Have you mooed today?"...

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

end of thread, other threads:[~2013-04-08  4:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-08  3:17 [Caml-list] Declaring a parameterized type in a .mli William Smith
2013-04-08  3:57 ` Ivan Gotovchits
2013-04-08  4:05   ` Markus Mottl
2013-04-08  4:09     ` Ivan Gotovchits

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