Path: news.daimi.aau.dk!olevi From: olevi@daimi.aau.dk (Ole Villumsen) Newsgroups: comp.lang.beta Subject: Re: Type checking, safety and templates Date: 27 Oct 1995 13:28:01 GMT Organization: DAIMI, Computer Science Dept. at Aarhus University Lines: 130 Message-ID: <46qmp1$m4n@krone.daimi.aau.dk> References: <46in44$q42@krone.daimi.aau.dk> NNTP-Posting-Host: indium.daimi.aau.dk Thanks to Kolbjørn Aambø for insisting on your questions. >> >In the C++ Standard draft the STL part it is claimed that almost all >> >Template related typechecking is *static*. Codegeneration is dependent ... >> the rule being static typechecking, as discussed above. As far as I can >> see, anything that you can do in C++, you can do in Beta and still >> have type safety. The dynamic type checking is only introduced to ... >As I remember from my little experience with BETA a lot of the typechecking >is actually matching of exit and enter list length. So given that, >how do you make a enter parameter so generic that it can take any type >as input, probably as a pointer but that is not what templates does, they >take static values that may vary considerably in size! You are right: transfer a reference instead of the actual data. If you consider this a difference, then it's a difference; I can't see its importance. In C++ you also should transfer references once your objects get big. >How can I make this max pattern find the max of ANY type that have >relational operator > ? so it can behave like ... >I of course want alt those BETA max functions to have the same name... >I guess that >max: (# a, b, c:: enter (a, b) > do > (if(true) > //( a > b) then a -> c; > else b -> c; > if) > exit c > #); >would NOT work I guess. Right - this is so because the standard types (integer, Boolean, char and real) are "outside" the inheritance hierarchy. A little speculation: Maybe they at least ought to have their own common superclass so you could go max: (# compType:< builtInType; a,b,res: compType; enter (a,b) do (if a>b then a -> res else b -> res) exit res #) ... x,y: @integer; ... (x,y) -> max(# compType::integer #) -> putInt; (* write the bigger value *) (You have to specify the type each time. This has a few advantages, like you can feed reals into the integer max function and they'll be converted, and your type errors with Booleans will be caught (soon, cf. Joergen Knudsen's article).) If you compare integers in several places, you'll probably want to declare intMax: max (# compType::integer #) once and for all. However, as long as you can't do the above, you'll have use references, as in max: (# compType:< object; gt:< (# a,b: ^compType; res: @boolean; enter(a[],b[]) do inner; exit res #); a,b,res: ^compType; enter (a[],b[]) do (if (a[],b[]) -> gt then a[] -> res[] else b[] -> res[] if) exit res[] #) ... x,y: @integerObject; greater: ^intergerObject; (* integerObject is a version of integer that can be used as an object *) ... (x[],y[]) -> max (# compType:: integerObject; gt::(# do (a>b) -> res #)#) -> greater[]; greater -> putInt; Again you can do intMax: max(# compType:: integerObject; gt::(# do (a>b) -> res #)#); ... (x[],y[]) -> intMax -> greater[]; - if you find that more convenient. The scheme has the additional advantage that you can compare objects of a certain type by different criteria each time - for instance, you can compare persons by name in one place in your program and by birth date in another place, using the same max pattern, only binding gt differently. >If I want to use my own string definition for UNICODE for instance >I know of no way to define the > infix relational operator.... >So I pobably have to live with the FOTRAN like GT that I implement >my self and that make my type less prominent than the build in >basic pattern that have infix relational operators.... True on the syntactic level. Beta's attepmt was exactly to provide *few* syntactic constructs powerful enough to let you do what you want; which (I think) is why they don't have operator overloading like in C++. On the semantic level, I think I'm giving you what you ask for - just call you UNICODE comparing algorithm from within your further binding of gt. >Please dont be too angry at me if I'm stupid, this is the only >way for be to find out about this matters. True - you're welcome. >By the way how is it going making a BETA on the Macintosh that >don't require MPW? That I don't know. Maybe someone from Mjølner will answer about this? Ole V.