Constrained genericity: Difference between revisions

Content added Content deleted
m (Updated tags D entries)
Line 357: Line 357:
let your_box = FloatBox.make_box_from_list [2.3; 4.5]</lang>
let your_box = FloatBox.make_box_from_list [2.3; 4.5]</lang>
Unfortunately, it is kind of cumbersome in that, for every type parameter we want to use for this generic type, we will have to explicitly create a module for the resulting type (i.e. <tt>BananaBox</tt>, <tt>FloatBox</tt>). And the operations on that resulting type (i.e. <tt>make_box_from_list</tt>) are tied to each specific module.
Unfortunately, it is kind of cumbersome in that, for every type parameter we want to use for this generic type, we will have to explicitly create a module for the resulting type (i.e. <tt>BananaBox</tt>, <tt>FloatBox</tt>). And the operations on that resulting type (i.e. <tt>make_box_from_list</tt>) are tied to each specific module.

=={{header|ooRexx}}==
ooRexx methods, routines, and collections are all untyped, so there are no language-level checks for type matches. Tests for identity need to be performed at runtime using mechanisms such as the object isA method.
<lang ooRexx>
call dinnerTime "yogurt"
call dinnerTime .pizza~new
call dinnerTime .broccoli~new


-- a mixin class that defines the interface for being "food", and
-- thus expected to implement an "eat" method
::class food mixinclass object
::method eat abstract

::class pizza subclass food
::method eat
Say "mmmmmmmm, pizza".

-- mixin classes can also be used for multiple inheritance
::class broccoli inherit food
::method eat
Say "ugh, do I have to?".

::routine dinnerTime
use arg dish
-- ooRexx arguments are typeless, so tests for constrained
-- types must be peformed at run time. The isA method will
-- check if an object is of the required type
if \dish~isA(.food) then do
say "I can't eat that!"
return
end
else dish~eat
</lang>



=={{header|Perl 6}}==
=={{header|Perl 6}}==