Anonymous user
Constrained genericity: Difference between revisions
→{{header|Perl 6}}: This time fer shure! --Bullwinkle
(→{{header|Ada}}: I think this solves the issue) |
(→{{header|Perl 6}}: This time fer shure! --Bullwinkle) |
||
Line 336:
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.
=={{header|Perl 6}}
{{works with|Rakudo|2010.09.17}}
<lang perl6>subset Eatable of Any where { .^can('eat') };
my Eatable @foodbox;▼
class Cake { method eat() {...} }
role FoodBox[Eatable ::T] {
has T %.foodbox;
}
class Yummy does FoodBox[Cake] { } # composes correctly
# class Yucky does FoodBox[Int] { } # fails to compose
say $foodbox.perl;</lang>
Output:
<lang>Yummy.new(foodbox => {})</lang>
=={{header|PicoLisp}}==
|