caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Jordan W <jordojw@gmail.com>
Cc: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] Record fields not reexported from functors.
Date: Mon, 11 May 2015 08:19:46 +0900	[thread overview]
Message-ID: <836FDA54-2F58-4BC1-8E4E-12438240E03C@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAPOA5_7X-wAxr8BwaUgz1u4rR00cphzgEKeQyPLwcNDT317NbQ@mail.gmail.com>

On 2015/05/11 06:58, Jordan W wrote:
> 
> I believe there is an issue with record fields and functors.
> It appears that while types are correctly exported from functors, the corresponding record field scopes are not. Here is an example.
> 
>    module type HasType = sig
>       type t
>     end
> 
>     module EchoModule (Input:HasType): (HasType with type t = Input.t) = (struct
>       type t = Input.t
>     end)
> 
>     module ClonedModuleWithRecordType = EchoModule (struct
>       type t = {innerRecordField: int}
>     end)
> 
>     (* This doesn't type check, but I can't see why it shouldn't. Record fields'
>        scopes should be reexported just like the types themselves.
> 
>       let myRecord: ClonedModuleWithRecordType.t = {
>         ClonedModuleWithRecordType.innerRecordField=10;
>       }

There is a misunderstanding here: the declaration “type t = Input.t” does not
re-export Input.t, it just defines a type abbreviation pointing to Input.t.
A type abbreviation does not contain field information.
You should qualify the field name with the original module name; unfortunately
there is no such module here since you defined the module inline.
Here is the type you get for ClonedModuleWithRecordType:
   module ClonedModuleWithRecordType : sig type t end
Since there is no module to refer to, all information about the type is lost.

The solution is to properly define the module argument:

   module MyRecord = struct type t = {innerRecordField: int} end
   module ClonedModuleWithRecordType = EchoModule (MyRecord)
   … {MyRecord.innerRecordField = 10 } …

which gives you:

   module ClonedModuleWithRecordType : sig type t = MyRecord.t end

Note that since 4.02 you can also omit the module name when the type is known.
But again, this will only work if there is a module name.

Jacques Garrigue

  reply	other threads:[~2015-05-10 23:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-10 21:58 Jordan W
2015-05-10 23:19 ` Jacques Garrigue [this message]
2015-05-11 17:24 ` Leo White

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=836FDA54-2F58-4BC1-8E4E-12438240E03C@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=jordojw@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).