caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Module abbreviation
@ 2009-12-15 16:39 Romain Bardou
  2009-12-15 16:56 ` [Caml-list] " Ashish Agarwal
  2009-12-15 17:01 ` Basile STARYNKEVITCH
  0 siblings, 2 replies; 8+ messages in thread
From: Romain Bardou @ 2009-12-15 16:39 UTC (permalink / raw)
  To: caml-list

Hello, dear Caml-list,

I have a file ast.mli. It has no .ml implementation as it contains only
type definitions.

I have a file toto.ml, which contains simply:

module A = Ast

So I only use it as an abbreviation, to write A.t instead of Ast.t for
instance.

However, at link-time, the following error occurs:

File "_none_", line 1, characters 0-1:
Error: Error while linking toto.cmo:
Reference to undefined global `Ast'

I found a workaround, which is to change ast.mli to put all type
definitions in a signature, such as:

module type Sig =
sig
  type t = ...
  ...
end

And then, in toto.ml:

module type A =
sig
  include Ast.Sig
end

Is there any better way to write such a module abbreviation, without
changing ast.mli? And, of course, without copying or renaming ast.mli
into ast.ml.

By the way, this is yet another evidence for the need of a construction
"sig of" which would take a module (with or without implementation) and
return its signature.

Thanks,

-- 
Romain Bardou


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

* Re: [Caml-list] Module abbreviation
  2009-12-15 16:39 Module abbreviation Romain Bardou
@ 2009-12-15 16:56 ` Ashish Agarwal
  2009-12-15 23:28   ` David Allsopp
       [not found]   ` <-5655904566200171061@unknownmsgid>
  2009-12-15 17:01 ` Basile STARYNKEVITCH
  1 sibling, 2 replies; 8+ messages in thread
From: Ashish Agarwal @ 2009-12-15 16:56 UTC (permalink / raw)
  To: Romain Bardou; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1640 bytes --]

If you only have a file ast.mli, you should not be able to write Ast.Sig
because you do not have a module named Ast. Please double check your
example. It cannot be working as you describe.

On Tue, Dec 15, 2009 at 11:39 AM, Romain Bardou <romain@bardou.fr> wrote:

> Hello, dear Caml-list,
>
> I have a file ast.mli. It has no .ml implementation as it contains only
> type definitions.
>
> I have a file toto.ml, which contains simply:
>
> module A = Ast
>
> So I only use it as an abbreviation, to write A.t instead of Ast.t for
> instance.
>
> However, at link-time, the following error occurs:
>
> File "_none_", line 1, characters 0-1:
> Error: Error while linking toto.cmo:
> Reference to undefined global `Ast'
>
> I found a workaround, which is to change ast.mli to put all type
> definitions in a signature, such as:
>
> module type Sig =
> sig
>  type t = ...
>  ...
> end
>
> And then, in toto.ml:
>
> module type A =
> sig
>  include Ast.Sig
> end
>
> Is there any better way to write such a module abbreviation, without
> changing ast.mli? And, of course, without copying or renaming ast.mli
> into ast.ml.
>
> By the way, this is yet another evidence for the need of a construction
> "sig of" which would take a module (with or without implementation) and
> return its signature.
>
> Thanks,
>
> --
> Romain Bardou
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> 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: 2499 bytes --]

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

* Re: [Caml-list] Module abbreviation
  2009-12-15 16:39 Module abbreviation Romain Bardou
  2009-12-15 16:56 ` [Caml-list] " Ashish Agarwal
@ 2009-12-15 17:01 ` Basile STARYNKEVITCH
  2009-12-17 11:35   ` Romain Bardou
  1 sibling, 1 reply; 8+ messages in thread
From: Basile STARYNKEVITCH @ 2009-12-15 17:01 UTC (permalink / raw)
  To: Romain Bardou; +Cc: caml-list

Romain Bardou wrote:
> Hello, dear Caml-list,
> 
> I have a file ast.mli. It has no .ml implementation as it contains only
> type definitions.


Then you should name that file ast.ml. Last time I tested (more than a year ago) n ast.ml file without corresponding 
ast.mli file is handled as if ast.mli was the output of ocamlc -i ast.ml.

Regards
-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***


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

* RE: [Caml-list] Module abbreviation
  2009-12-15 16:56 ` [Caml-list] " Ashish Agarwal
@ 2009-12-15 23:28   ` David Allsopp
       [not found]   ` <-5655904566200171061@unknownmsgid>
  1 sibling, 0 replies; 8+ messages in thread
From: David Allsopp @ 2009-12-15 23:28 UTC (permalink / raw)
  To: 'Ashish Agarwal', 'Romain Bardou'; +Cc: 'caml-list'

Ashish Agarwal wrote:
> If you only have a file ast.mli, you should not be able to write Ast.Sig
because you do not have a module named Ast.

This isn't true - the include statement works at a type system level
(because you're dealing with a signature) and therefore only a .cmi file is
required. It does not generate any work for the linker so a module called
Ast is not actually needed when linking.

> Please double check your example. It cannot be working as you describe.

I'm afraid you should have checked - the example given compiles (try ocamlc
-o foo ast.mli toto.ml with suitable substitutions for the "..."s)

Romain Bardou wrote:

> I have a file ast.mli. It has no .ml implementation as it contains only
> type definitions.

This is fine

> I have a file toto.ml, which contains simply:
> 
> module A = Ast

But as this involves a linker instruction you need an actual module - hence
the error you're seeing. I guess you could argue that the module statement
could check to see if Ast only contains type definitions and relax the need
for an actual module but in the general case Ast could contain values and so
you need a module to link against.

> I found a workaround, which is to change ast.mli to put all type
> definitions in a signature, such as:

This workaround works because you take the whole thing back to the type
system so module implementations are not required by the linker.


David


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

* Re: [Caml-list] Module abbreviation
       [not found]   ` <-5655904566200171061@unknownmsgid>
@ 2009-12-16  3:17     ` Ashish Agarwal
  0 siblings, 0 replies; 8+ messages in thread
From: Ashish Agarwal @ 2009-12-16  3:17 UTC (permalink / raw)
  To: David Allsopp; +Cc: Romain Bardou, caml-list

[-- Attachment #1: Type: text/plain, Size: 1892 bytes --]

> the example given compiles

Surprising! I see your point about the types working out, but this also
requires the additional assumption that the module type defined by ast.mli
will be ascribed specifically to a module named Ast. I suppose this is
consistent with how ocaml associates file names with modules so it works
out.


On Tue, Dec 15, 2009 at 6:28 PM, David Allsopp <dra-news@metastack.com>wrote:

> Ashish Agarwal wrote:
> > If you only have a file ast.mli, you should not be able to write Ast.Sig
> because you do not have a module named Ast.
>
> This isn't true - the include statement works at a type system level
> (because you're dealing with a signature) and therefore only a .cmi file is
> required. It does not generate any work for the linker so a module called
> Ast is not actually needed when linking.
>
> > Please double check your example. It cannot be working as you describe.
>
> I'm afraid you should have checked - the example given compiles (try ocamlc
> -o foo ast.mli toto.ml with suitable substitutions for the "..."s)
>
> Romain Bardou wrote:
>
> > I have a file ast.mli. It has no .ml implementation as it contains only
> > type definitions.
>
> This is fine
>
> > I have a file toto.ml, which contains simply:
> >
> > module A = Ast
>
> But as this involves a linker instruction you need an actual module - hence
> the error you're seeing. I guess you could argue that the module statement
> could check to see if Ast only contains type definitions and relax the need
> for an actual module but in the general case Ast could contain values and
> so
> you need a module to link against.
>
> > I found a workaround, which is to change ast.mli to put all type
> > definitions in a signature, such as:
>
> This workaround works because you take the whole thing back to the type
> system so module implementations are not required by the linker.
>
>
> David
>
>

[-- Attachment #2: Type: text/html, Size: 2594 bytes --]

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

* Re: [Caml-list] Module abbreviation
  2009-12-15 17:01 ` Basile STARYNKEVITCH
@ 2009-12-17 11:35   ` Romain Bardou
  2009-12-18  6:55     ` Basile STARYNKEVITCH
  0 siblings, 1 reply; 8+ messages in thread
From: Romain Bardou @ 2009-12-17 11:35 UTC (permalink / raw)
  To: Basile STARYNKEVITCH; +Cc: caml-list

Basile STARYNKEVITCH wrote:
> Romain Bardou wrote:
>> Hello, dear Caml-list,
>>
>> I have a file ast.mli. It has no .ml implementation as it contains only
>> type definitions.
> 
> 
> Then you should name that file ast.ml. Last time I tested (more than a
> year ago) n ast.ml file without corresponding ast.mli file is handled as
> if ast.mli was the output of ocamlc -i ast.ml.
> 
> Regards

Yes, this seems to be the easiest way. It's too bad that this implies
having a .cmo to link against just for some type definitions, though.

Thanks again,

-- 
Romain Bardou


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

* Re: [Caml-list] Module abbreviation
  2009-12-17 11:35   ` Romain Bardou
@ 2009-12-18  6:55     ` Basile STARYNKEVITCH
  2009-12-18 12:06       ` Romain Bardou
  0 siblings, 1 reply; 8+ messages in thread
From: Basile STARYNKEVITCH @ 2009-12-18  6:55 UTC (permalink / raw)
  To: Romain Bardou; +Cc: caml-list

Romain Bardou wrote:
> Basile STARYNKEVITCH wrote:
>> Romain Bardou wrote:
>>> Hello, dear Caml-list,
>>>
>>> I have a file ast.mli. It has no .ml implementation as it contains only
>>> type definitions.
>>
>> Then you should name that file ast.ml. Last time I tested (more than a
>> year ago) n ast.ml file without corresponding ast.mli file is handled as
>> if ast.mli was the output of ocamlc -i ast.ml.
>>
>> Regards
> 
> Yes, this seems to be the easiest way. It's too bad that this implies
> having a .cmo to link against just for some type definitions, though.


Why is that bad?  The *.cm[oi] files are the only ones containing the processed type & module information, and we 
obviously don't want ocamlc to reparse ast.mli each time it is needed.

Regards

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***


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

* Re: [Caml-list] Module abbreviation
  2009-12-18  6:55     ` Basile STARYNKEVITCH
@ 2009-12-18 12:06       ` Romain Bardou
  0 siblings, 0 replies; 8+ messages in thread
From: Romain Bardou @ 2009-12-18 12:06 UTC (permalink / raw)
  To: Basile STARYNKEVITCH; +Cc: caml-list

Basile STARYNKEVITCH wrote:
> Romain Bardou wrote:
>> Basile STARYNKEVITCH wrote:
>>> Romain Bardou wrote:
>>>> Hello, dear Caml-list,
>>>>
>>>> I have a file ast.mli. It has no .ml implementation as it contains only
>>>> type definitions.
>>>
>>> Then you should name that file ast.ml. Last time I tested (more than a
>>> year ago) n ast.ml file without corresponding ast.mli file is handled as
>>> if ast.mli was the output of ocamlc -i ast.ml.
>>>
>>> Regards
>>
>> Yes, this seems to be the easiest way. It's too bad that this implies
>> having a .cmo to link against just for some type definitions, though.
> 
> 
> Why is that bad?  The *.cm[oi] files are the only ones containing the
> processed type & module information, and we obviously don't want ocamlc
> to reparse ast.mli each time it is needed.

Indeed, but a .cmi would be enough :)

Cheers,

-- 
Romain Bardou


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

end of thread, other threads:[~2009-12-18 12:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-15 16:39 Module abbreviation Romain Bardou
2009-12-15 16:56 ` [Caml-list] " Ashish Agarwal
2009-12-15 23:28   ` David Allsopp
     [not found]   ` <-5655904566200171061@unknownmsgid>
2009-12-16  3:17     ` Ashish Agarwal
2009-12-15 17:01 ` Basile STARYNKEVITCH
2009-12-17 11:35   ` Romain Bardou
2009-12-18  6:55     ` Basile STARYNKEVITCH
2009-12-18 12:06       ` Romain Bardou

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