develooper Front page | perl.perl6.language | Postings from May 2005

Re: Default precedence level of user defined infix ops

Thread Previous
From:
Sam Vilain
Date:
May 18, 2005 14:35
Subject:
Re: Default precedence level of user defined infix ops
Message ID:
428BB505.3050800@vilain.net
Luke Palmer wrote:
>>And how do I explicitly define the precedence?
> Using the `tighter`, `looser`, and `equiv` traits.  You specify
> precedence in terms of the precedence of other existing ops.
>     sub infix:<.>(&f, &g) is looser(&infix:<+>) {...}

This is interesting.  So, infix:< > is similar to Haskell's
() circumfix operator, like ((+) 1 2) ≍ (1 + 2).

Which method does &infix:<+> refer to, if you have;

  multi sub infix:<+>(Num $i, Num $j) { $i.add($j) }
  multi sub infix:<+>(Set $i, Set $j) { $i.union($j) }

?

Are these automatically locked to the same level, in fact, does it
make sense for any 'operator' (ie, the sub's short name) to exist
in multiple precedence levels at once?

Or is it simply a major ParseF*** to have to determine precedence
/after/ determining types of operands?

Sam.

Thread Previous


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