caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Modules and record fields
Date: Mon, 26 May 2014 11:14:45 +0200	[thread overview]
Message-ID: <20140526091445.GB24582@frosties> (raw)
In-Reply-To: <CAPFanBGcvF1wa0kDAnaf_J0EQPwdU3uP++SB3WMh7jmZXQtsfg@mail.gmail.com>

On Sun, May 25, 2014 at 05:02:46PM +0200, Gabriel Scherer wrote:
> When I write M.v.f, it is not always the case that the field f is
> exported by the module M. Consider for example:
> 
> module A = struct
>   type t = { f: int }
> end
> 
> module M = struct
>   open A
>   let v = { f = 1 }
>   type u = { f : string }
> end
> 
> print_int M.v.f
> 
> This rightly fails (with a warning) as one should write M.v.A.f to be
> fully precise about the scope. Note that M.v.M.f or M.(v.f) would have
> a completely different (and wrong) meaning.

Here is another example:

module V2 = struct
  type t = { x:int; y:int; }
  let make x y =  { x; y; }
end

module V3 = struct
  type t = { x:int; y:int; z:int; }
  let make x y z =  { x; y; z; }
  let of_v2 v = { x = v.V2.x; y = v.V2.y; V3.z = 0; }
  let to_v2 v = { V2.x = v.x; V2.y = v.y; }
end

let v3_of_v2 v = { V3.x = v.V2.x; V3.y = v.V2.y; V3.z = 0; }

MfG
	Goswin

      reply	other threads:[~2014-05-26  9:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-25 10:30 Ollie Frolovs
2014-05-25 10:45 ` Gabriel Scherer
2014-05-25 10:59 ` Gabriel Kerneis
2014-05-25 12:46   ` Ollie Frolovs
2014-05-25 13:57     ` Gabriel Scherer
2014-05-25 14:56       ` Ollie Frolovs
2014-05-25 15:02         ` Gabriel Scherer
2014-05-26  9:14           ` Goswin von Brederlow [this message]

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=20140526091445.GB24582@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    /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).