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

package-level type alias

2 replies
michael hohn
Joined: 2009-11-27,
User offline. Last seen 42 years 45 weeks ago.

Hello,

Using the scala 2.8 repl, the definition

type ObjTreeList = ListBuffer[Tuple2[EObject, String]]

works and can be used later in classes etc.

For the whole file, with structure

package foo
...
type ObjTreeList = ListBuffer[Tuple2[EObject, String]]
...

the eclipse plugin gives the error message

expecting class or object

and as result the file won't compile.

Are package-level type aliases not allowed, or is this a plugin issue?

If package-level aliases are not allowed, how can I get a meaningful
name for a final class like ListBuffer, short of introducing a whole
new class just to wrap a ListBuffer special case?

Thank you,
Mike

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: package-level type alias

On Mon, Mar 01, 2010 at 11:20:10AM -0800, michael hohn wrote:
> Are package-level type aliases not allowed, or is this a plugin issue?

This is a large chunk of why package objects were created.

> If package-level aliases are not allowed, how can I get a meaningful
> name for a final class like ListBuffer, short of introducing a whole
> new class just to wrap a ListBuffer special case?

package foo {
type LB[T] = scala.collection.mutable.ListBuffer[T]
}

See the many files called package.scala in trunk for endless examples.

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: package-level type alias

On Mon, Mar 01, 2010 at 11:44:57AM -0800, Paul Phillips wrote:
> package foo {
> type LB[T] = scala.collection.mutable.ListBuffer[T]
> }

Oops, of course I mean

package object foo { ... }

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