What is type and what is type constructor in scala -


i'm bit confused understanding of type in scala means.

in documents read list[int] type , list type constructor.

but keyword type means when write following?

val ls: _root_.scala.collection.immutable.list.type = scala.collection.immutable.list 

and how type related type can defined field in trait example.

what keyword type means when write following

type member defined on object in scala.

suppose have class , companion object:

class foo(a: string)  object foo {   def apply(a: string) = new foo } 

now suppose want write method accepts object foo input. what's type?

if write this:

def somemethod(fooobj: foo) = fooobj.apply("x") // doesn't compile 

it's not going compile. foo refers type of instance of class (i.e. 1 returned new foo("x") or foo("x")). that's why objects have type member can refer own type:

def somemethod(fooobj: foo.type) = fooobj.apply("x") // compiles! 

in specific example list.type type of companion object of list. here's couple of examples hope clarify means:

val listobj: list.type = list val anemptylist: list[int] = listobj.empty[int] // list() val alistofintegers: list[int] = listobj.range(1, 4) // list[(1, 2, 3) 

and how type related type can defined field in trait example.

and how type related type can defined field in trait example.

the type keyword defines type member. .type is type member. conceptually it's every object in scala has type member named type, this:

object foo {   type type = foo } 

obviously won't compile, gives idea of may like.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -