scala - How to make a right-associative infix operator? -


i have associative operation >>. problem cost linearly depends on size of left operand. expression formed sequence of n applications of >> like

a >> >> >> >> >> ... >> 

it has quadratic cost in terms of n, because default infix operators left-associative. how make right-associative cost of such expression kept linear in terms of n?

a found solution. scala reference says in 6.12.3 infix operations:

the associativity of operator determined operator’s last character. operators ending in colon ‘:’ right-associative. other operators left-associative.

therefore enough rename >> >>:.

it took me time realize while a >> b desugared a.>>(b), a >>: b desugared b.>>:(a). had define >>: as

def >>:(x: t): t = x >> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -