Untyped macros in infix position

21 views
Skip to first unread message

Nick Clarke

unread,
Mar 8, 2013, 5:38:41 AM3/8/13
to scala...@googlegroups.com
I'm expecting the answer to be a straight 'no', but is it possible to write an untyped macro that can be used in infix position? I'm trying to replicate Haskell's 'where' clause, so I'd like to do something like the following:

implicit class HasWhere(val exp : _) {
def where(block : Unit) = macro whereInfix
}

def whereInfix(c : Context)(block : c.Expr[Unit]) = {
import c.universe._

val exp = Select(c.prefix.tree, TermName("exp"))
val Expr(Block((inner, _))) = block
val newinner = inner :+ exp
Block(newinner : _*)
}

Feels like the implicit approach is bound to fail, however, because it's not possible to type 'exp' until after macro evaluation. Just wonder if I'm missing a trick, however.

Cheers,

Nick

Nick Clarke

unread,
Mar 8, 2013, 5:40:28 AM3/8/13
to scala...@googlegroups.com
I should mention that I've read the earlier post about infix macros, which pretty much suggested a 'no'; this is just wondering if there's some sneaky alternative solution I haven't thought of.

Eugene Burmako

unread,
Mar 8, 2013, 6:21:05 AM3/8/13
to scala-user
Currently the argument on the left has to be typechecked first before
any implicit resolution kicks in. The fact that you can write "class
foo(x: _)" is an oversight - the underscore syntax is supposed to be
working only in untyped macros. I'd be grateful if you submitted a bug
about that.

If this functionality is an important thing to have for you, please,
ping me mid next week, and I'll see what I can do. Maybe it's possible
to put some hack in place that would do exactly what you want :)

Nick Clarke

unread,
Mar 8, 2013, 8:31:39 AM3/8/13
to scala...@googlegroups.com
Issue created at https://issues.scala-lang.org/browse/SI-7230

I'll send a message sometime next week. It's not a big thing, but it could enable some cool stuff.

Thanks!

Nick
Reply all
Reply to author
Forward
0 new messages