Slides from LASER 2012

Timon Gehr timon.gehr at gmx.ch
Thu Sep 20 15:39:03 PDT 2012


On 09/20/2012 11:33 PM, bearophile wrote:
> Timon Gehr:
>
>> mixin ADT!q{ Tree(T): Leaf(T x), Node(Tree a, Tree b) };
>>
>> DynRange!T fringe(T)(Tree!T t){
>>     return t.match!(
>>         (Leaf l) => cons(l.x, empty),
>>         (Node n) => chain(n.a.fringe, n.b.fringe).dynRange,
>>     );
>> }
>>
>> bool sameFringe(T)(Tree!T t1, Tree!T t2){
>>     return equal(t1.fringe, t2.fringe);
>> }
>
> What's the purpose of the dynRange suffix here?
> (Node n) => chain(n.a.fringe, n.b.fringe).dynRange
>

chain has type Result. dynRange takes an arbitrary range and transforms
it into a range with the same value/vs reference behaviour whose static
type depends only on the element type.

> Maybe a "~" operator can be defined for such dynRanges, to avoid the
> chain().

Yes, that should certainly be done. (it can be more efficient.)



More information about the Digitalmars-d-announce mailing list