Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
51
Task/Constrained-genericity/Sather/constrained-genericity.sa
Normal file
51
Task/Constrained-genericity/Sather/constrained-genericity.sa
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
abstract class $EDIBLE is
|
||||
eat;
|
||||
end;
|
||||
|
||||
class FOOD < $EDIBLE is
|
||||
readonly attr name:STR;
|
||||
eat is
|
||||
#OUT + "eating " + self.name + "\n";
|
||||
end;
|
||||
create(name:STR):SAME is
|
||||
res ::= new;
|
||||
res.name := name;
|
||||
return res;
|
||||
end;
|
||||
end;
|
||||
|
||||
class CAR is
|
||||
readonly attr name:STR;
|
||||
create(name:STR):SAME is
|
||||
res ::= new;
|
||||
res.name := name;
|
||||
return res;
|
||||
end;
|
||||
end;
|
||||
|
||||
class FOODBOX{T < $EDIBLE} is
|
||||
private attr list:LLIST{T};
|
||||
create:SAME is
|
||||
res ::= new;
|
||||
res.list := #;
|
||||
return res;
|
||||
end;
|
||||
add(c :T) is
|
||||
self.list.insert_back(c);
|
||||
end;
|
||||
elt!:T is loop yield self.list.elt!; end; end;
|
||||
end;
|
||||
|
||||
class MAIN is
|
||||
main is
|
||||
box ::= #FOODBOX{FOOD}; -- ok
|
||||
box.add(#FOOD("Banana"));
|
||||
box.add(#FOOD("Amanita Muscaria"));
|
||||
|
||||
box2 ::= #FOODBOX{CAR}; -- not ok
|
||||
box2.add(#CAR("Punto")); -- but compiler let it pass!
|
||||
|
||||
-- eat everything
|
||||
loop box.elt!.eat; end;
|
||||
end;
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue