develooper Front page | perl.perl6.language | Postings from October 2006

Re: class interface of roles

Thread Previous | Thread Next
From:
Jonathan Lang
Date:
October 10, 2006 20:40
Subject:
Re: class interface of roles
Message ID:
ef30550b0610102039s43ff6b34g9ba70184e3215f2a@mail.gmail.com
TSa wrote:
> Jonathan Lang wrote:
> > TSa wrote:
> >  > Dispatch depends on a partial ordering of roles.
> >
> > Could someone please give me an example to illustrate what is meant by
> > "partial ordering" here?
>
> In addition to Matt Fowles explanation I would like to
> give the following example lattice build from the roles
>
>    role A { has $.x }
>    role B { has $.y }
>    role C { has $.z }
>
> There can be the four union combined roles A|B, A|C, B|C
> and A|B|C which complete the type lattice:
>
>                       Any={}
>                      /  |  \
>                     /   |   \
>                    /    |    \
>                   /     |     \
>                  /      |      \
>                A={x}  B={y}  C={z}
>                 | \    / \    / |
>                 |  \  /   \  /  |
>                 |   \/     \/   |
>                 |   /\     /\   |
>                 |  /  \   /  \  |
>                 | /    \ /    \ |
>           A|B={x,y} A|C={x,z} B|C={y,z}
>                  \      |      /
>                   \     |     /
>                    \    |    /
>                     \   |   /
>                      \  |  /
>                  A|B|C={x,y,z}

So if I'm reading this right, a class that does both A and B should be
"lower" in the partial ordering than a class that does just one or the
other.  And if A does B, then you'll never have a class that does just
A without also doing B, which trims out a few possible nodes and paths
from the lattice for practical purposes:

                      Any={}
                        |  \
                        |   \
                        |    \
                        |     \
                        |      \
                      B={y}  C={z}
                       / \      |
                      /   \     |
                     /     \    |
                    /       \   |
                   /         \  |
                  /           \ |
          A|B={x,y}           B|C={y,z}
                 \             /
                  \           /
                   \         /
                    \       /
                     \     /
                 A|B|C={x,y,z}

I note that while the lattice is related to whatever role hierarchies
may or may not exist, it is not the same as them.  In particular,
roles that have no hierarchal relationship to each other _will_ exist
in the same lattice.  In fact, all roles will exist in the same
lattice, on the first row under "Any".  Right?  Or does the fact that
"A does B" mean that A would be placed where "A|B" is, and "A|C" would
end up in the same node as "A|B|C"?

> This lattice can then be used for type checks and specificity
> comparisons in dispatch. BTW, such a lattice can be calculated lazily
> from any set of packages. In pure MMD the selected target has to be
> the most specific in all dispatch relevant positions.

By "most specific", you'd mean "closest to the top"?

-- 
Jonathan "Dataweaver" Lang

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About