This page is no longer maintained — Please continue to the home page at www.scala-lang.org

What's the type of a singleton object and how to use it?

No replies
Johannes Rudolph
Joined: 2008-12-17,
User offline. Last seen 29 weeks 21 hours ago.

In a particular case, how can I refer to the type of None:

trait Container[X]

def onlyForNone(x:Container[None]) = //... doesn't compile since None
is no type
def onlyForNone(x:Container[None.type]) = //... compiles, but can't
be used since 'Container[object None]' is not the same as
'Container[None.this]'

Would that work, one could use the Option hierarchy for both values
and type-level Booleans as I proposed here:

http://gist.github.com/182249

I had to introduce my own version of the Option hierarchy with an
additional 'trait None' to have a type which to match over. Is there
another possibility?

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland