Slides from LASER 2012

bearophile bearophileHUGS at lycos.com
Thu Sep 20 09:59:14 PDT 2012


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);
> }
>
> for suitable definitions of ADT, DynRange/dynRange, cons and 
> empty.  So
> those would be nice additions to Phobos. Obviously this would 
> look even
> better:
>
> mixin ADT!q{ Tree(T): Leaf(T x), Node(Tree a, Tree b) };
>
> DynRange!T fringe(T)(Tree!T t) => 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) => t1.fringe == 
> t2.fringe;

And thank you for the code example.

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list