From: Andreas Rossberg <rossberg@ps.uni-sb.de>
To: OCAML <caml-list@inria.fr>
Subject: Re: [Caml-list] illegal permutation of structure fields?
Date: Mon, 23 Jul 2001 18:07:12 +0200 [thread overview]
Message-ID: <3B5C4BB0.70D3B74B@ps.uni-sb.de> (raw)
In-Reply-To: <20010723172755.A5259@pauillac.inria.fr>
Xavier Leroy wrote:
>
> > file: bla.ml
> > ---------------------------------------------------------------------------
> > module type FOO = sig
> > val x : int
> > val y : int
> > end
> > ---------------------------------------------------------------------------
> >
> > file: bla.mli
> > ---------------------------------------------------------------------------
> > module type FOO = sig
> > val y : int
> > val x : int
> > end
> > ---------------------------------------------------------------------------
> >
> > This yields the following error:
> > Illegal permutation of structure fields
> >
> > Why is this illegal? Wouldn't it be very straightforward to normalize
> > the signatures (e.g. sort elements by name) before matching them?
>
> That's more or less what old versions of OCaml did, but it's
> incorrect. The reason is that a module signature determine the layout
> of the corresponding structure: if
>
> module A : sig val x : int val y : int end
>
> then A is represented as the tuple (value_of_x, value_of_y), while
>
> module B : sig val y : int val x : int end
>
> is represented as the tuple (value_of_y, value_of_x).
Then the followup question of course is: isn't it trivial to use a
canonical layout instead, where the tuple components are sorted wrt. to
the corresponding fields' label? This way layout is invariant wrt
permutation in signatures. Or is there a particular problem with such a
scheme?
(BTW, the same holds for record and variant types, where Ocaml does not
allow reordering of fields/constructors either.)
Best regards,
- Andreas Rossberg
--
Andreas Rossberg, rossberg@ps.uni-sb.de
"Computer games don't affect kids.
If Pac Man affected us as kids, we would all be running around in
darkened rooms, munching pills, and listening to repetitive music."
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next prev parent reply other threads:[~2001-07-23 16:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-23 13:04 Markus Mottl
2001-07-23 15:27 ` Xavier Leroy
2001-07-23 16:07 ` Andreas Rossberg [this message]
2001-07-26 7:14 ` Xavier Leroy
2001-07-26 8:42 ` Markus Mottl
2001-07-23 16:36 ` Markus Mottl
2001-07-25 22:27 ` John Max Skaller
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=3B5C4BB0.70D3B74B@ps.uni-sb.de \
--to=rossberg@ps.uni-sb.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