How do you check if a type is a subtype of any Function0?

22 views
Skip to the first unread message

Johannes Rudolph

unread,
8 May 2012, 02:35:0208/05/2012
to scala-i...@googlegroups.com
This seems like such a common thing, though I can't find the best way
do this. What doesn't work is

tpe <:< FunctionClass(0).tpe

as I understand it because `FunctionClass(0).tpe` is the polymorphic
type without a concrete instantiation of the type parameter.

What seems to work is

tpe.baseType(FunctionClass(0)) != NoType

or

tpe <:< tpe.baseType(FunctionClass(0))

but isn't there a simpler way?

--
Johannes

-----------------------------------------------
Johannes Rudolph
http://virtual-void.net

Paul Phillips

unread,
8 May 2012, 02:48:5008/05/2012
to scala-i...@googlegroups.com
On Mon, May 7, 2012 at 11:35 PM, Johannes Rudolph
<johannes...@googlemail.com> wrote:
>
> but isn't there a simpler way?

tpe.typeSymbol isSubClass FunctionClass(0)

Johannes Rudolph

unread,
8 May 2012, 02:51:1608/05/2012
to scala-i...@googlegroups.com
Thanks. I knew there had to be a simpler way.

Eugene Burmako

unread,
8 May 2012, 03:13:4108/05/2012
to scala-i...@googlegroups.com
Someone just said not to use typeSymbols, right? No trolling, just trying to understand

Paul Phillips

unread,
8 May 2012, 04:04:0708/05/2012
to scala-i...@googlegroups.com
On Tue, May 8, 2012 at 12:13 AM, Eugene Burmako <eugene....@epfl.ch> wrote:
> Someone just said not to use typeSymbols, right? No trolling, just trying to
> understand

I was insufficiently specific. What you want to avoid is exactly what
was causing SI-5769 - mixing operations which normalize with
operations which don't. If you want to be more careful, there's
always

tpe.normalize match {
case TypeRef(_, sym, _) if sym isSubClass FunctionClass(0) => ...
}

But if you happen to know isSubClass deals with aliases transparently
then you know it's not going to hurt you here.

It would be better if there were fewer chainsaw-juggling carneys
hanging around, yes.
Reply all
Reply to author
Forward
0 new messages