Re: [BLACKBOX] Matrix slices - syntax

From: [at]} <Josef>
Date: Fri, 2 Apr 2010 08:47:57 +0200

----boundary-LibPST-iamunique-969615456_-_-
Content-type: text/plain

Languages in the Pascal family (Pascal, Modula-2, Oberon, CP)
always employed a type eqivalence principle named
'Name Equivalence' rather than 'Structural Equivalence'.
Two types are compatible if they refer to one and the same type
constructor (ARRAY, RECORD, PROCEDURE).
For reusing such a type constructor you must give it a name and
reuse the name of the type.

The main reason, as far as I know, is that name equivalence
is more expressive than structural equivalence because the former
also allows you to express 'incompatibility' by introducing multiple
type constructors.

Look for the famous example of complex numbers,
which may be expressed in cartesian or polar coordinates.
Both representations have the same structure but are clearly
incompatible.

TYPE
  Complex1 = RECORD x, y: REAL END;
  Complex2 = RECORD r, phi: REAL END ;

The compiler may also be simplified a bit and type checking is faster
but I think these are not the main reasons.
There are only a few exceptions from the name equivalence
principle. One is the usage of open arrays, which have been
introduced for string and vector operations. Fixed sized arrays
follow the name equivalence rule just like records do.

In your case, why don't you define M3Desc as:
  M3Desc = ARRAY 3 OF V3Desc;
which would make it explicit that the element type of M3Desc
is V3Desc.

- Josef

----- Original Message -----
From: Douglas G. Danforth
To: BLACKBOX{([at]})nowhere.xy
Sent: Thursday, April 01, 2010 4:23 AM
Subject: [BLACKBOX] Matrix slices - syntax


Folks,

I don't understand this.
If I define a procedure that takes an ARRAY OF REAL and
pass it an row of a matrix then that works BUT if I specialize
the procedure to take an ARRAY 3 OF REAL and pass it a
row of a matrix ARRAY 3,3 OF REAL then the compiler complains.

TYPE
 VDesc = ARRAY OF REAL;
 V3Desc = ARRAY 3 OF REAL;
 MDesc = ARRAY OF ARRAY OF REAL;
 M3Desc = ARRAY 3,3 OF REAL;

  PROCEDURE Q (IN v: VDesc); BEGIN END Q;
  PROCEDURE Q3 (IN v: V3Desc); BEGIN END Q3;

  PROCEDURE Test;
  VAR m3: M3Desc;
  BEGIN
    Q(m3[0]); (* works *)
    Q3(m3[0]) (* fails! incompatible assignment *)
  END Test;

The "slice" m3[0], which is the first row of m3, is accepted by a routine
that accepts general non specific vectors but that same slice which
has length 3 is rejected by a routine that wants vectors of length 3.
Why?
I really don't understand the strong typing in this case.

-Doug Danforth



---- To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-969615456_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIExhbmd1YWdlcyBpbiB0aGUgUGFzY2FsIGZhbWls
eSAoUGFzY2FsLCBNb2R1bGEtMiwgT2Jlcm9uLCBDUClccGFyDQphbHdheXMgZW1wbG95ZWQgYSB0
eXBlIGVxaXZhbGVuY2UgcHJpbmNpcGxlIG5hbWVkIFxwYXINCidOYW1lIEVxdWl2YWxlbmNlJyBy
YXRoZXIgdGhhbiAnU3RydWN0dXJhbCBFcXVpdmFsZW5jZScuXHBhcg0KVHdvIHR5cGVzIGFyZSBj
b21wYXRpYmxlIGlmIHRoZXkgcmVmZXIgdG8gb25lIGFuZCB0aGUgc2FtZSB0eXBlXHBhcg0KY29u
c3RydWN0b3IgKEFSUkFZLCBSRUNPUkQsIFBST0NFRFVSRSkuXHBhcg0KRm9yIHJldXNpbmcgc3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RvcnMgb2YgbGVuZ3RoIDMuXHBhcg0KV2h5
P1xwYXINCkkgcmVhbGx5IGRvbid0IHVuZGVyc3RhbmQgdGhlIHN0cm9uZyB0eXBpbmcgaW4gdGhp
cyBjYXNlLlxwYXINClxwYXINCi1Eb3VnIERhbmZvcnRoXHBhcg0KXHBhcg0KXHBhcg0KXHBhcg0K
LS0tLSBUbyB1bnN1YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJTSUdOT0ZGIEJM
QUNLQk9YIiB0byBMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0hccGFyDQpccGFyDQpccGFyDQotLS0t
XHBhcg0KVG8gdW5zdWJzY3JpYmUsIHNlbmQgYSBtZXNzYWdlIHdpdGggYm9keSAiU0lHTk9GRiBC
TEFDS0JPWCIgdG8gTElTVFNFUlZATElTVFMuT0JFUk9OLkNIfX0AgDAxvQ==
----boundary-LibPST-iamunique-969615456_-_---
Received on Fri Apr 02 2010 - 08:47:57 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:33 UTC