Skip to content

Instantly share code, notes, and snippets.

@etorreborre
Last active March 24, 2024 14:55
Show Gist options
  • Save etorreborre/5078824 to your computer and use it in GitHub Desktop.
Save etorreborre/5078824 to your computer and use it in GitHub Desktop.
A good summary of Scala types from http://bit.ly/XjSVKw
class Outer {
class Inner
type Type
}
trait Trait
object Object extends Outer {
val inner = new Inner
}
class OuterP[A] {
class InnerP[B]
}
class annot extends annotation.StaticAnnotation
trait <*>[A1, A2]
trait T1
trait T2
class TypesOfTypes {
def singletonType: Object.type = ??? // 3.2.1
def typeProjection: Outer#Inner = ??? // 3.2.2
def typeDesignator: Object.Type = ??? // 3.2.3
def parameterizedType: OuterP[T1] = ??? // 3.2.4
def tupleType: (T1, T2) = ??? // 3.2.5
def annotatedType: T1 @annot = ??? // 3.2.6
def compoundType: T1 with T2 = ??? // 3.2.7
def infixType: T1 <*> T2 = ??? // 3.2.8
def functionType: T1 => T2 = ??? // 3.2.9
def existentialType: Q forSome { type Q <: T1 } = ??? // 3.2.10
def nullaryMethodType: T1 = ???
def methodType(x: T1)(y: T1): T1 = ???
def parameterizedMethod[A](x: A)(y: A): A = ???
def byNameParameter(x: => T1): T1 = ???
def repeatedParameter(x: T1*): T1 = ???
type TypeAlias = Outer
type TypeAliasP[A] = OuterP[A]
type AbstractType <: Outer
type AbstractTypeP[A] <: OuterP[A]
}
/****
scala> typeOf[TypesOfTypes].declarations.toList map (m => fullyInitializeSymbol(m)) map (m => if (m.isType) m.defString else m.tpe_*) >
()TypesOfTypes
=> Object.type
=> Outer#Inner
=> Object.Type
=> OuterP[T1]
=> (T1, T2)
=> T1 @annot
=> T1 with T2
=> <*>[T1,T2]
=> T1 => T2
=> Q forSome { type Q <: T1 }
=> T1
(x: T1)(y: T1)T1
[A](x: A)(y: A)A
(x: => T1)T1
(x: T1*)T1
type TypeAlias = Outer
type TypeAliasP[A] = OuterP[A]
type AbstractType <: Outer
type AbstractTypeP[A] <: OuterP[A]
****/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment