Re: [Oberon] Clarifying type compatibility in Oberon-07
-----Original Message-----
From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of J rg Sent: Friday, 6 October 2017 1:55 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Clarifying type compatibility in Oberon-07
Hi Andreas
Of course we could do so, but I wonder why? If I understand you correctly you want to allow the following VAR a: ARRAY 30 OF CHAR; b: ARRAY 30 OF CHAR; a := b;
Currently, this is not allowed, because there are several ways to allow this already Method 1: VAR a, b: ARRAY 30 OF CHAR; Method 2: TYPE String30 = ARRAY 30 OF CHAR; VAR a: String30; b: String30;
What if the two declarations are separate e.g.? -------------------------------- MODULE M0; VAR a*: ARRAY 32 OF INTEGER; ... ... -------------------------------- MODULE M1; IMPORT M0; VAR a: ARRAY 32 OF INTEGER; BEGIN a := M0.a; ... ... ------------------------------- or this one: ------------------------------- MODULE Array6; VAR g: ARRAY 10 OF INTEGER; PROCEDURE P; VAR a: ARRAY 10 OF INTEGER; BEGIN a := g; END P; END Array6. ------------------------------- If the programmer has chosen to use anonymous arrays it might well be reasonable to assume he is not concerned about name equivalence so why should he be inconvenienced but prohibiting assignments? Surely not just because it conflicts with somebody else's personal taste? I'm sure there are many more examples. However, it is premature to discuss solutions before *every single one* of the possible practical scenarios have been elaborated. To do so risks unintentionally prohibiting useful applications or allowing badly-behaved ones. Once this is done a test suite of examples to exercise all of these (positive and negative) cases should be developed. As well as confirming that the eventual solution is correct it would form a useful addition to the report for those who enjoy contemplating these issues or for other compiler implementers. Regards, Chris Burrows CFB Software http://www.astrobe.com
Chris We are talking about a typed language are we? Not C or assembler... If something is named or not has nothing to do with if they should be compatible or not. MODULE X; TYPE A = ARRAY 30 OF INTEGER; VAR a*: A; MODULE Y; IMPORT X TYPE B = ARRAY 30 OF INTEGER; VAR b: B b := A.a So, you would allow this? br Jörg
Am 08.10.2017 um 02:26 schrieb Chris Burrows <chris@cfbsoftware.com>:
-----Original Message-----
From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of J rg Sent: Friday, 6 October 2017 1:55 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Clarifying type compatibility in Oberon-07
Hi Andreas
Of course we could do so, but I wonder why? If I understand you correctly you want to allow the following VAR a: ARRAY 30 OF CHAR; b: ARRAY 30 OF CHAR; a := b;
Currently, this is not allowed, because there are several ways to allow this already Method 1: VAR a, b: ARRAY 30 OF CHAR; Method 2: TYPE String30 = ARRAY 30 OF CHAR; VAR a: String30; b: String30;
What if the two declarations are separate e.g.?
-------------------------------- MODULE M0;
VAR a*: ARRAY 32 OF INTEGER;
... ... -------------------------------- MODULE M1;
IMPORT M0;
VAR a: ARRAY 32 OF INTEGER; BEGIN a := M0.a; ... ... -------------------------------
or this one:
------------------------------- MODULE Array6;
VAR g: ARRAY 10 OF INTEGER;
PROCEDURE P; VAR a: ARRAY 10 OF INTEGER; BEGIN a := g; END P;
END Array6. -------------------------------
If the programmer has chosen to use anonymous arrays it might well be reasonable to assume he is not concerned about name equivalence so why should he be inconvenienced but prohibiting assignments? Surely not just because it conflicts with somebody else's personal taste?
I'm sure there are many more examples. However, it is premature to discuss solutions before *every single one* of the possible practical scenarios have been elaborated. To do so risks unintentionally prohibiting useful applications or allowing badly-behaved ones. Once this is done a test suite of examples to exercise all of these (positive and negative) cases should be developed. As well as confirming that the eventual solution is correct it would form a useful addition to the report for those who enjoy contemplating these issues or for other compiler implementers.
Regards, Chris Burrows CFB Software http://www.astrobe.com
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Sorry, I meant b:= X.a (not A.a) Jörg
Am 08.10.2017 um 06:09 schrieb Jörg <joerg.straube@iaeth.ch>:
Chris
We are talking about a typed language are we? Not C or assembler... If something is named or not has nothing to do with if they should be compatible or not.
MODULE X; TYPE A = ARRAY 30 OF INTEGER; VAR a*: A;
MODULE Y; IMPORT X TYPE B = ARRAY 30 OF INTEGER; VAR b: B
b := A.a
So, you would allow this?
br Jörg
Am 08.10.2017 um 02:26 schrieb Chris Burrows <chris@cfbsoftware.com>:
-----Original Message-----
From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of J rg Sent: Friday, 6 October 2017 1:55 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Clarifying type compatibility in Oberon-07
Hi Andreas
Of course we could do so, but I wonder why? If I understand you correctly you want to allow the following VAR a: ARRAY 30 OF CHAR; b: ARRAY 30 OF CHAR; a := b;
Currently, this is not allowed, because there are several ways to allow this already Method 1: VAR a, b: ARRAY 30 OF CHAR; Method 2: TYPE String30 = ARRAY 30 OF CHAR; VAR a: String30; b: String30;
What if the two declarations are separate e.g.?
-------------------------------- MODULE M0;
VAR a*: ARRAY 32 OF INTEGER;
... ... -------------------------------- MODULE M1;
IMPORT M0;
VAR a: ARRAY 32 OF INTEGER; BEGIN a := M0.a; ... ... -------------------------------
or this one:
------------------------------- MODULE Array6;
VAR g: ARRAY 10 OF INTEGER;
PROCEDURE P; VAR a: ARRAY 10 OF INTEGER; BEGIN a := g; END P;
END Array6. -------------------------------
If the programmer has chosen to use anonymous arrays it might well be reasonable to assume he is not concerned about name equivalence so why should he be inconvenienced but prohibiting assignments? Surely not just because it conflicts with somebody else's personal taste?
I'm sure there are many more examples. However, it is premature to discuss solutions before *every single one* of the possible practical scenarios have been elaborated. To do so risks unintentionally prohibiting useful applications or allowing badly-behaved ones. Once this is done a test suite of examples to exercise all of these (positive and negative) cases should be developed. As well as confirming that the eventual solution is correct it would form a useful addition to the report for those who enjoy contemplating these issues or for other compiler implementers.
Regards, Chris Burrows CFB Software http://www.astrobe.com
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-----Original Message----- From: Jörg [mailto:joerg.straube@iaeth.ch] Sent: Sunday, 8 October 2017 2:40 PM To: chris@cfbsoftware.com; ETH Oberon and related systems Subject: Re: [Oberon] Clarifying type compatibility in Oberon-07
Chris
We are talking about a typed language are we? Not C or assembler...
Yes. However I prefer to keep an open mind and take a pragmatic approach to these sorts of issues rather than a strict dogmatic approach. As soon as we accept the concept of open array parameters the strict name compatibility rule is compromised. Pascal went too far along the dogmatic route. Oberon represents a more pragmatic approach. It is a product resulting from decades of the author's real world experience.
If something is named or not has nothing to do with if they should be compatible or not.
In the context of name equivalence vs. structural equivalence that statement is false.
MODULE X; TYPE A = ARRAY 30 OF INTEGER; VAR a*: A;
MODULE Y; IMPORT X TYPE B = ARRAY 30 OF INTEGER; VAR b: B
b := X.a
So, you would allow this?
That is a different scenario and would need to be considered separately. The conclusion does not necessarily follow from my previous example. However, the short answer is 'No'. Exporting 'a' serves no purpose without also exporting 'A'. If A is exported as well then currently the answer is 'Yes'. The Astrobe compiler accepts it (and so does the RISC5 compiler). It all depends on your interpretation of the words 'same', 'equal', 'identical'. In 'Programming in Oberon' (2015) when discussing parameter compatibility, Wirth says: "If a formal parameter type denotes an array structure, its corresponding actual parameter must be an array of the *identical type*. This implies that it must have *elements of identical type* and the *same bounds* of the index range." That sounds more like structure compatibility than name compatibility to me. I'm not saying you are wrong and I am right. I'm saying that our interpretations are different. I have used the interpretation that I believe is most useful when programming microcontrollers with Oberon. If a later version of the Oberon Report appears which convinces me my interpretation is unsound then I'll reconsider. Regards, Chris Burrows CFB Software http://www.astrobe.com
On Sun, Oct 8, 2017, at 07:00 AM, Chris Burrows wrote:
It all depends on your interpretation of the words 'same', 'equal', 'identical'.
In 'Programming in Oberon' (2015) when discussing parameter compatibility, Wirth says:
"If a formal parameter type denotes an array structure, its corresponding actual parameter must be an array of the *identical type*. This implies that it must have *elements of identical type* and the *same bounds* of the index range." That sounds more like structure compatibility than name compatibility to me.
Wirth always uses "same" and "identical" as synonyms. If you compare the Report and PIO, they are often exchanged. However, name equivalence *implies* structural equivalence, but the viceversa doesn't hold. You can find this argument in any type theory book. This is what he means in that sentence (otherwise he would have used *equivalent* or other another term for equality, not implication), because in that paragraph he's introducing the concept of the open array, where structural equivalence is not enough. -- Diego Sardina
Chris
I have used the interpretation that I believe is most useful when programming microcontrollers with Oberon.
Don't get me wrong. I fully understand your argument. During my career, I wrote quite some low-level code in Oberon myself and know that its typing can really be a kick in the… Quite some SYSTEM stuff has to be used; this is the reason why I write IMPORT S := SYSTEM :-P And if you already have a variable you are tempted to re-use it for several different stuff (with different types). But nevertheless: Oberon is not mainly written having us in mind, Oberon should be a general, type-bound and hence safe language as the compiler detects a lot of accidental typos on its own. I’m open to relax the type system. But the examples, I heard so far do not convince me enough. If you have to write ARRAY 10 OF INTEGER over and over again, you’ll be better off declaring all types you need for your drivers in a separate MODULE where you export your type collection. br Jörg
Chris A question and I’m really curious to get your opinion Would you allow this as well? MODULE X VAR a*: RECORD real, img: REAL END; MODULE Y; IMPORT X; VAR b: RECORD x, y: REAL END; b := X.a If no, why ARRAYs but not RECORDs? if yes, why do we need typing then? Jörg
Am 08.10.2017 um 07:52 schrieb Jörg <joerg.straube@iaeth.ch>:
Chris
I have used the interpretation that I believe is most useful when programming microcontrollers with Oberon.
Don't get me wrong. I fully understand your argument. During my career, I wrote quite some low-level code in Oberon myself and know that its typing can really be a kick in the… Quite some SYSTEM stuff has to be used; this is the reason why I write IMPORT S := SYSTEM :-P
And if you already have a variable you are tempted to re-use it for several different stuff (with different types). But nevertheless: Oberon is not mainly written having us in mind, Oberon should be a general, type-bound and hence safe language as the compiler detects a lot of accidental typos on its own. I’m open to relax the type system. But the examples, I heard so far do not convince me enough. If you have to write ARRAY 10 OF INTEGER over and over again, you’ll be better off declaring all types you need for your drivers in a separate MODULE where you export your type collection.
br Jörg
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On 2017-10-08 08:20, Jörg wrote:
Chris
A question and I’m really curious to get your opinion Would you allow this as well?
MODULE X VAR a*: RECORD real, img: REAL END;
MODULE Y; IMPORT X; VAR b: RECORD x, y: REAL END; b := X.a
Even C uses name equivalence for record types (structs), but the reason for this is that the variables may have different alignment (even though they have the same structure). -- August
On 2017-10-08 08:20, Jörg wrote:
Chris A question and I’m really curious to get your opinion Would you allow this as well? MODULE X VAR a*: RECORD real, img: REAL END; MODULE Y; IMPORT X; VAR b: RECORD x, y: REAL END; b := X.a
Even C uses name equivalence for record types (structs), but the reason for this is that the variables may have different alignment (even though they have the same structure).
In Oberon the alignment is part of the type. You can see BYTE as an INTEGR with another alignment. BYTE aligns on byte boundary, INTEGER aligns on 32bit boundary. So in Oberon they would structurally not match. br Jörg
Apropos types (and hidden type casts)… Be aware of the following compiler behavior: VAR b: BYTE; SYSTEM.PUT(adr, b + 40); (* compiler assumes b + 40 is BYTE, hence generates STB *) SYSTEM.PUT(adr, 40 + b); (* compiler assumes 40 + b is INTEGER, hence generates STW *) br Jörg P.S. You have to slightly modify ORTool to see this important difference..
Am 08.10.2017 um 08:20 schrieb Jörg <joerg.straube@iaeth.ch>:
Chris
A question and I’m really curious to get your opinion Would you allow this as well?
MODULE X VAR a*: RECORD real, img: REAL END;
MODULE Y; IMPORT X; VAR b: RECORD x, y: REAL END; b := X.a
If no, why ARRAYs but not RECORDs? if yes, why do we need typing then?
Jörg
Am 08.10.2017 um 07:52 schrieb Jörg <joerg.straube@iaeth.ch>:
Chris
I have used the interpretation that I believe is most useful when programming microcontrollers with Oberon.
Don't get me wrong. I fully understand your argument. During my career, I wrote quite some low-level code in Oberon myself and know that its typing can really be a kick in the… Quite some SYSTEM stuff has to be used; this is the reason why I write IMPORT S := SYSTEM :-P
And if you already have a variable you are tempted to re-use it for several different stuff (with different types). But nevertheless: Oberon is not mainly written having us in mind, Oberon should be a general, type-bound and hence safe language as the compiler detects a lot of accidental typos on its own. I’m open to relax the type system. But the examples, I heard so far do not convince me enough. If you have to write ARRAY 10 OF INTEGER over and over again, you’ll be better off declaring all types you need for your drivers in a separate MODULE where you export your type collection.
br Jörg
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Folks, The topic "Clarifying type compatibility in Oberon-07" has died! It died 50 posts ago! Its time to pick a new "significant" topic. Move on, move on ... -Doug Danforth
participants (5)
-
August Karlstrom -
Chris Burrows -
Diego Sardina -
Douglas G Danforth -
Jörg