Path: news.daimi.aau.dk!jlk From: jlk@daimi.aau.dk (Jorgen Lindskov Knudsen) Newsgroups: comp.lang.beta Subject: Re: Strong Typing in BETA Date: 3 Jun 1997 21:01:46 GMT Organization: DAIMI, Computer Science Dept. at Aarhus University Lines: 106 Message-ID: <5n20nq$i3i$1@gjallar.daimi.aau.dk> References: <33942FF8.6C9EEC3B@fernuni-hagen.de> Reply-To: jlknudsen@daimi.aau.dk (Jorgen Lindskov Knudsen) NNTP-Posting-Host: arsenic.daimi.aau.dk X-Newsreader: NN version 6.5.1 (NOV) Xref: news.daimi.aau.dk comp.lang.beta:11125 In <33942FF8.6C9EEC3B@fernuni-hagen.de> Arnd Poetzsch-Heffter writes: >Hi, >I am currently learning BETA and have a question about typing. >Consider the following BETA program: > Program : (# > Super : (# > AttrPattern :< Object; > attr : ^AttrPattern > Init :< Object > #) > Sub : Super (# > AttrPattern ::< (# i: @int #) > Init ::< (# do 1 -> attr.i #) > #) > sp: ^Super; > sb: ^Sub; > do &Sub[] -> sb; > sb -> sp; >(1) &Super[] -> sp.attr; (**** Dynmic Type Error ???? *) >(2) &sp.Init > #) >In line (1), a reference to a newly created Super-object X is assigned >to the attribute attr of a Sub-object. X has no attribute i. > Is this assignment correct according to the typing rules of BETA? Or: > Does this assignment cause a runtime error? Or: > What happens with the call of Init in line (2) which executes Sub.Init > (as far as I understand) and which accesses attr.i ? >Thanks for your help! (As the above program is the first BETA program >I wrote, it might contain some errors, but I hope the underlying >problem is nevertheless clear.) Let us start by correcting the few errors in your program. It then reads (including the extra stuff in the beginning to make it acceptable for the compiler): ORIGIN '~beta/basiclib/v1.5/betaenv' --- program: descriptor --- (# Super: (# AttrPattern :< Object; attr : ^AttrPattern; Init :< Object #); Sub : Super (# AttrPattern ::< (# i: @integer #); Init ::< (# do 1 -> attr.i #) #); sp: ^Super; sb: ^Sub; do &Sub[] -> sb[]; sb[] -> sp[]; (*1*) &Super[] -> sp.attr[]; (**** Dynmic Type Error ???? *) (*2*) &sp.Init #) When running the program, you will get a run-time error in (*1*) as you also anticipated. This implies, that the program never reaches line (*2*) so the question on the execution of Init become void. Why then do we get a run-time (so-called qualification) error in (*1*) ? Let us see the defn. of 'sp' - the qualification of 'sp' is 'Super'. This implies, that the qualification of 'sp.attr' is 'AttrPattern'. Since AttrPattern is a virtual attribute in 'Super', the dynamic qualification of 'sp.attr' is controlled by the exact object being referenced by the sp reference. In this case this object is an instance of 'Sub'. This gives us, that the dynamic qualification of 'sp.attr' at this place in the program is 'Sub.AttrPattern'. This implies, that for the reference assignment in (*1*) to be legal, the object reference being assigned to 'sp.attr' _must_ be an instance of 'Sub.AttrPattern', or an instance of a subpattern of 'Sub.AttrPattern'. The object being generated by the '&Super[]' is an instance of 'Super'. And 'Super' is not a subpattern of 'Sub.AttrPattern'. Which gives us the dynamic type error !!! I hope this helps. If not, please ask again. Good luck with your further investigations in the BETA world. Regards, Jorgen Lindskov Knudsen -- * Jorgen Lindskov Knudsen | Phone: +45 8942 3188 * * Dept. of Computer Science | Direct: +45 8942 3233 * * University of Aarhus | Fax: +45 8942 3255 * * Ny Munkegade, Building 540 | GSM: +45 2099 7357 *