Path: news.daimi.aau.dk!news.uni-c.dk!sunic!pipex!howland.reston.ans.net!swrinde!ihnp4.ucsd.edu!network.ucsd.edu!mbk From: mbk@inls1.ucsd.edu (Matt Kennel) Newsgroups: comp.object,comp.lang.eiffel,comp.lang.sather,comp.lang.beta,comp.lang.modula3 Subject: Re: Cows, Hogs & Farms Followup-To: comp.object,comp.lang.eiffel,comp.lang.sather,comp.lang.beta,comp.lang.modula3 Date: 6 Jan 1995 04:31:34 GMT Organization: Institute For Nonlinear Science, UCSD Lines: 80 Message-ID: <3eih36$94g@network.ucsd.edu> References: <1995Jan5.183534.10065@schbbs.mot.com> NNTP-Posting-Host: gibbs.ucsd.edu X-Newsreader: TIN [version 1.1 PL8] Xref: news.daimi.aau.dk comp.object:23476 comp.lang.eiffel:7114 comp.lang.sather:1386 comp.lang.beta:197 comp.lang.modula3:3294 David L. Shang (shang@corp.mot.com) wrote: : But by Sather, run-time type check is always a neccessity. And by Eiffel's : covariance, a system validation is required for the above case. : By Cluster, runtime type check is not necessary for the above cases. It is only : necessary when a herbivore cannot identify whether the food is its food. This : happens only in the case of a reverse/cross assignment: : : Runtime type check is not an very important issue. The keypoint is that whether : the language can say the way you want! : David Shang You can do most of Cluster's static solution in Sather, and I guess Eiffel. type $HERBIVORE is -- generic herbivore, no specific foodtype known. name:STR; eat_or_barf(food:$PLANT); type $HERBIVORE{FOODT < $PLANT} < $HERBIVORE is name:STR; eat(food:FOODT) -- must be able to eat end; class COW < $HERBIVORE{GRASS} is -- blah blah end; class HOG < $HERBIVORE{CORN} is -- blah blah end; class MONOCULTUREFARM{FOODT, ANIMALT < $HERBIVORE{FOODT} } is attr livestock : LIST{ANIMALT}; -- type is known at compile time attr foodstock : LIST{FOODT}; -- type is known dinnertime is loop elsie ::= livestock.elt!; dinner ::= foodstock.elt; elsie.eat(dinner); -- sooouie! no run-time check needed. end; end; end; class FREEFORMFARM is attr livestock : LIST{$HERBIVORE}; attr foodstock : LIST{$PLANT}; dinnertime is loop animal ::= livestock.elt!; dinner ::= foodstock.elt!; animal.eat_or_barf(dinner); -- run-time check in there. end; end; end; In Cluster I guess, you could have written MONOCULTUREFARM with just one type parameter (the ANIMAL) and then extract its preferred food from that. You can't do that in Sather I don't think but there isn't so much harm, as it's a compile time error to instantiate it with a bad combination of herbivore and food. cheers Matt -- -Matt Kennel mbk@inls1.ucsd.edu -Institute for Nonlinear Science, University of California, San Diego -*** AD: Archive for nonlinear dynamics papers & programs: FTP to -*** lyapunov.ucsd.edu, username "anonymous".