- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
type alias at top level ; package
Mon, 2011-12-05, 17:58
Why is OK to do this:
object Foo { type X = Int }
but not at top (package) level:
type X = Int // error
Related: does a package implicitly define a top-level object?
Also, please let me know if there is a more suitable list for such questions.
Thanks!
Mon, 2011-12-05, 18:47
#2
Re: type alias at top level ; package
On Mon, Dec 5, 2011 at 8:58 AM, Sophie wrote:
> Why is OK to do this:
>
> object Foo { type X = Int }
>
> but not at top (package) level:
>
> type X = Int // error
>
> Related: does a package implicitly define a top-level object?
>
> Also, please let me know if there is a more suitable list for such
> questions.
>
I think this one is most suitable for scala-user. But no harm done
asking it here :-). The answer (use a pcakage object) is correct.
Cheers
Wed, 2011-12-07, 20:21
#3
Re: type alias at top level ; package
Thanks, that works.
A current downside is REPL and IDE line noise, as
package object Foo { type X = Int }
will clutter up the REPL (and Scala IDE) with Foo.X instead of X, which
is noise for the intended use.
Relatedly, here is a REPL output:
val capitals = Map("France" -> "Paris")
capitals: scala.collection.immutable.Map[java.lang.String,
java.lang.String] = Map(France -> Paris)
When in the REPL what I'd much prefer:
capitals = Map(France -> Paris)
On 2011-12-05 11:42:29 -0600, martin odersky said:
> On Mon, Dec 5, 2011 at 8:58 AM, Sophie wrote:
>> Why is OK to do this:
>>
>> object Foo { type X = Int }
>>
>> but not at top (package) level:
>>
>> type X = Int // error
>>
>> Related: does a package implicitly define a top-level object?
>>
>> Also, please let me know if there is a more suitable list for such
>> questions.
>>
> I think this one is most suitable for scala-user. But no harm done
> asking it here :-). The answer (use a pcakage object) is correct.
>
> Cheers
>









package object Foo { type X = Int}
Marius
On Mon, Dec 5, 2011 at 6:58 PM, Sophie <itsme213 [at] hotmail [dot] com> wrote: