Path: news.daimi.aau.dk!krab From: Kresten Krab Thorup Newsgroups: comp.lang.beta Subject: Re: Is overwriting possible in BETA? Date: 23 Jun 1997 21:19:27 +0200 Organization: DAIMI, Computer Science Dept. of Aarhus Univ. Lines: 57 Message-ID: References: <339BEE9A.B0F69DF@fernuni-hagen.de> NNTP-Posting-Host: california.daimi.aau.dk Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Newsreader: Gnus v5.4.59/Emacs 19.33 Xref: news.daimi.aau.dk comp.lang.beta:11155 Arnd Poetzsch-Heffter writes: > Is it possible in BETA to overwrite an attribute of a superpattern > within a subpattern? Consider e.g. the following fragment (as I > have no BETA execution environment, the fragment might contain some > syntax errors, sorry for that): > > Super: > (# Attr :< SuperAttrPattern { or: Attr : SuperAttrPattern } > #); > > Sub : Super > (# Attr : SomePattern_Not_Subpattern_Of_SuperAttrPattern; > #) > > Such a situation is often useful to refine implementations (E.g. > to refine a singly linked list implementation where the list length > is computed by a recursive procedure pattern to an implementation > where the length is stored with each element). It is not possible to override a virtual so that it will be available polymorphicly. This has been talked about, but never fully designed and implemented. In my suggestion for introducing virtuals in Java (ECOOP'97) I have included this ability. Basically, this allows two patterns to be associated with a virtual: 1) the qualification, and 2) the default-binding. If this was to be implemented in BETA, it might look like this: Super: (# A: (# ... #); AA: A(# ... #) attr:< A = AA; (* qualification A, binding AA *) #) Sub: Super (# B: A (# ... #); BB: B (# ... #); attr::< B = BB; (* qualification B, binding BB *) #) The qualification designates "what you can see", i.e. the static type of the attribute. You can think of it as an interface for the virtual attribute. The defult-binding is "what you get", i.e. the actual pattern that will be instantiated at run time. The typechecking rule would be that a further binding (::<) needs to have a qualification that is a specialization of the qualification of the declaration it futher-binds. A default-binding just has to be a specialization of the qualifying pattern for the same declaration; thus the default bindings for two successive further-binding don't have to be direct specializations of each other. --Kresten