Skip to content

Instantly share code, notes, and snippets.

@jorgeortiz85
Created July 15, 2010 19:07
Show Gist options
  • Save jorgeortiz85/477368 to your computer and use it in GitHub Desktop.
Save jorgeortiz85/477368 to your computer and use it in GitHub Desktop.
scala> object Foo
defined module Foo
scala> val x = Foo
x: Foo.type = Foo$@24753433
scala> val y = identity(Foo)
y: object Foo = Foo$@24753433
@retronym
Copy link

Singleton types aren't inferred as type arguments. Not sure of the rationale.

scala> identity[Foo.type](x)
res2: Foo.type = Foo$@20724356

scala> def i[X <: Singleton](x: X) = x
i: [X <: Singleton](x: X)X

scala> i(x)
<console>:9: error: inferred type arguments [object Foo] do not conform to method i's type parameter bounds [X <: Singleton]
       i(x)
       ^
scala> i[Foo.type](x)
res4: Foo.type = Foo$@20724356

@jorgeortiz85
Copy link
Author

Hmm... yeah, I think I remember Martin saying that singleton types aren't inferred because then a singleton type would pretty much always be inferred.

Also, James Iry found this gem:

scala> def test(x: Foo.type) = x
test: (x: Foo.type)object Foo

scala> test(x)
res6: object Foo = Foo$@600ab1bf

@jorgeortiz85
Copy link
Author

From @collinmbulluck: Somehting to do with type inference and stable vs unstable identifiers?

scala> val x = Foo
x: Foo.type = Foo$@600ab1bf

scala> var y = Foo
y: object Foo = Foo$@600ab1bf

@paulp
Copy link

paulp commented Jul 16, 2010

a) If singleton types were inferred, we wouldn't have the martin classic "I invite everyone to change this rule, and observe what breaks!"

https://lampsvn.epfl.ch/trac/scala/ticket/1208

b) See also comments in:

https://lampsvn.epfl.ch/trac/scala/ticket/3494 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment