develooper Front page | perl.perl6.users | Postings from August 2020

Combining multiple "is..." traits into one?

Thread Next
From:
Stuart Hungerford
Date:
August 11, 2020 20:35
Subject:
Combining multiple "is..." traits into one?
Message ID:
CAG+kMrFkNVPVRst8ijTpVzqncJ2ka+x_eAgnpzwBV5of_q37TA@mail.gmail.com
Hi,

I'm working with roles where the mixing-in classes and roles need to
have some mixin-specific notion of equality. So I have an Equality
role that can also be
mixed in as needed:

role Equality {
  method equal(Equality:D) of Bool:D {...}
}

To make using the role easier I've created an infix operator "=/=". To
give the infix operator predcitable semantics I need to specify the
precedence and the associativity with traits:

sub infix:<=/=>(Equality:D \x, Equality:D \y) of Bool:D is
equiv(&infix:<==>) is assoc<chain> is export {
  x.equal(y)
}

Is there some way to combine traits to a more succinct trait?  Something like:

subset Equivalence of Routine where {magic}...;

sub infix:<=/=>(Equality:D \x, Equality:D \y) of Bool:D is equivalence
is export;

Would a custom version of the trait_mod:<is> routine do the trick?

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