Browse thread
[Caml-list] illegal permutation of structure fields?
-
Markus Mottl
-
Xavier Leroy
- Andreas Rossberg
- Markus Mottl
- John Max Skaller
-
Xavier Leroy
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Andreas Rossberg <rossberg@p...> |
| Subject: | Re: [Caml-list] illegal permutation of structure fields? |
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