Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006336OCamlOCaml typingpublic2014-03-05 09:592014-04-04 05:24
Reporterlpw25 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionno change required 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0006336: `module type of` applied to module aliases
DescriptionIt is potentially surprising that the following code compiles on trunk:

  module M : sig
    type 'a t = private { foo: 'a; bar: 'a }
    val example : int t
  end = struct
    type 'a t = { foo: 'a; bar: 'a }
    let example = {foo=0;bar=0}
  end

  module A = M

  module type S = module type of A
  module N : S = A
  module U : S = A
  let z = [N.example;U.example]

whilst the following does not:

  module M : sig
    type 'a t = private { foo: 'a; bar: 'a }
    val example : int t
  end = struct
    type 'a t = { foo: 'a; bar: 'a }
    let example = {foo=0;bar=0}
  end

  module type S = module type of M
  module N : S = M
  module U : S = M
  let z = [N.example;U.example]

Since `module A = M` now introduces an alias, it seems that operations on `A` should behave like operations on `M`, but this is not the case for `module type of` which returns a strengthened signature from `A` but a weakened signature from `M`.

Of course if `module type of` returned the strengthened version then it would already do the right thing, but since it doesn't, it might be best if `module type of` treated module aliases specially.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0010997)
garrigue (manager)
2014-03-06 07:16

This result is not surprising: unrolling the signature of an alias results in the strengthened signature of the original module, so that taking "module type of" this signature will give you this already strengthened signature.
This is just the standard behavior for module aliases.
This is in contrast with applying "module type of" to the original module, which will give you the signature of the module, but not strengthened.
In both cases, "module type of" does no strengthening.
Indeed "module type of" is a hack, and the result is not strictly functional, but this is by design.
(0011001)
lpw25 (developer)
2014-03-06 10:11

> This result is not surprising: unrolling the signature of an alias results in the strengthened signature of the original module, so that taking "module type of" this signature will give you this already strengthened signature.

Indeed, I didn't find it surprising, but the people who brought it to my attention did, and I can see their point. When you tell people that A is an alias for B, they assume that A and B can be used interchangeably. For the most part this reasoning works with module aliases, but `module type of` is a place where that reasoning breaks down.

Is there any particular reason to not treat module aliases specially in `module type of` by fetching the weakened version of the type of the module that is aliased?
(0011220)
garrigue (manager)
2014-04-04 05:24

> Is there any particular reason to not treat module aliases specially in `module type of` by fetching the weakened version of the type of the module that is aliased?

Backward compatibility.
The first version of your code is accepted by previous versions of OCaml (post 3.12, of course), and the second version is refused.

- Issue History
Date Modified Username Field Change
2014-03-05 09:59 lpw25 New Issue
2014-03-06 07:16 garrigue Note Added: 0010997
2014-03-06 07:16 garrigue Assigned To => garrigue
2014-03-06 07:16 garrigue Status new => feedback
2014-03-06 10:11 lpw25 Note Added: 0011001
2014-03-06 10:11 lpw25 Status feedback => assigned
2014-04-04 05:24 garrigue Note Added: 0011220
2014-04-04 05:24 garrigue Status assigned => resolved
2014-04-04 05:24 garrigue Resolution open => no change required


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker