Ken McDonald | 1 Feb 02:04
Picon

Why is the compiler complaining about default argument values?

In a class, the following three method signatures are defined:


def insert(at: Int, insertee: Mark, direction: Direction = Forward): Mark = ...
def insert(at: Mark, insertee: Mark, direction: Direction = Forward): Mark = ...
def insert(at: Mark, content: Content, direction: Direction);

The types of arguments ensure that there can be no possible ambiguity as to which is called (there is no inheritance between Content and Mark). However, the compiler says:

    error: in trait Element, multiple overloaded alternatives of method insert define default arguments.
trait Element {

Why is this a problem? There's no erasure happening, so I don't see why there would be any run-time ambiguity.

Thanks,
Ken
Sciss | 1 Feb 02:08
Picon
Gravatar

Re: Why is the compiler complaining about default argument values?

unfortunately you cannot mix overloading and default arguments... (well, you can have _one_ method with
defaults, but not more than one). this was done for simplicity, even if it would be possible to allow both
overloading and multiple default arguments.

http://stackoverflow.com/questions/4652095/why-does-the-scala-compiler-disallow-overloaded-methods-with-default-arguments

best, -sciss-


On 1 Feb 2012, at 01:04, Ken McDonald wrote:

> In a class, the following three method signatures are defined:
> 
> 	def insert(at: Int, insertee: Mark, direction: Direction = Forward): Mark = ...
> 	def insert(at: Mark, insertee: Mark, direction: Direction = Forward): Mark = ...
> 	def insert(at: Mark, content: Content, direction: Direction);
> 
> The types of arguments ensure that there can be no possible ambiguity as to which is called (there is no
inheritance between Content and Mark). However, the compiler says:
> 
>     error: in trait Element, multiple overloaded alternatives of method insert define default arguments.
> trait Element {
> 
> Why is this a problem? There's no erasure happening, so I don't see why there would be any run-time ambiguity.
> 
> Thanks,
> Ken

Santiago Basulto | 1 Feb 05:08
Picon

Advance Actors documentation or tutorials

Hello friends,

i've got a pretty good background with Java concurrency, but i can't
find any advanced tutorials / documentation for Scala Actors.

The best I found is this (it's in the docs site):
http://docs.scala-lang.org/overviews/core/actors.html

I've already read:

Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition
(Odersky, et al)

Programming Scala: Scalability = Functional Programming + Objects
(Payne, et al)

Thank you very much!

--

-- 
Santiago Basulto.-

Naftoli Gugenheim | 1 Feb 08:36
Picon

Is this a known bug?

Anyone know whether this is in JIRA, or if it should be? This was revealed by ScalaCheck, on 2.9.1: scala.collection.mutable.ArrayBuffer().slice(102450392, -2045033354) throws an out of memory error.

Philipp Haller | 1 Feb 09:08
Picon
Picon
Favicon

Re: Advance Actors documentation or tutorials

Hi,

On Feb 1, 2012, at 5:08 AM, Santiago Basulto wrote:

> Hello friends,
> 
> i've got a pretty good background with Java concurrency, but i can't
> find any advanced tutorials / documentation for Scala Actors.

You might want to have a look at the book "Actors in Scala" (Artima, 2011). It contains more advanced
documentation for Scala Actors, as well as material on Akka actors.

Cheers,
Philipp

> 
> The best I found is this (it's in the docs site):
> http://docs.scala-lang.org/overviews/core/actors.html
> 
> I've already read:
> 
> Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition
> (Odersky, et al)
> 
> Programming Scala: Scalability = Functional Programming + Objects
> (Payne, et al)
> 
> Thank you very much!
> 
> -- 
> Santiago Basulto.-

Chris Marshall | 1 Feb 09:22
Picon
Favicon
Gravatar

RE: Inferring type of None

I think you'll find that Nothing is a subtype of Int

> Subject: Re: [scala-user] Inferring type of None
> From: contact-ezOpgnVUB8c@public.gmane.org
> Date: Tue, 31 Jan 2012 18:19:31 +0000
> CC: scala-user-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> To: edmondo.porcu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
>
> first of all, B <: Int doesn't make sense. Int is a final type, there cannot be any subtype of Int
>

Edmondo Porcu | 1 Feb 09:56
Picon

Re: Inferring type of None

Yes sorry I oversimplified the example.


The solution I found to let the type inferer work is the following:

None.asInstanceOf[Option[MyType]]

Best Regards


2012/2/1 Chris Marshall <oxbow_lakes <at> hotmail.com>
I think you'll find that Nothing is a subtype of Int

> Subject: Re: [scala-user] Inferring type of None
> From: contact-ezOpgnVUB8c@public.gmane.org
> Date: Tue, 31 Jan 2012 18:19:31 +0000
> CC: scala-user-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> To: edmondo.porcu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

>
> first of all, B <: Int doesn't make sense. Int is a final type, there cannot be any subtype of Int
>


Lars Hupel | 1 Feb 10:15
Picon
Favicon

Re: Inferring type of None

Can we please stop using `asInstanceOf` to "let the type inferencer
work"? That's nowhere near a "solution" to your problem.

If you need a `None` which is of type `Option[X]`, use `Option.empty[X]`.

Alec Zorab | 1 Feb 10:15

Re: Inferring type of None

Alternatively: Option.empty[MyType]

On 1 February 2012 08:56, Edmondo Porcu <edmondo.porcu@...> wrote:
> Yes sorry I oversimplified the example.
>
> The solution I found to let the type inferer work is the following:
>
> None.asInstanceOf[Option[MyType]]
>
> Best Regards
>
>
> 2012/2/1 Chris Marshall <oxbow_lakes@...>
>>
>> I think you'll find that Nothing is a subtype of Int
>>
>> > Subject: Re: [scala-user] Inferring type of None
>> > From: contact@...
>> > Date: Tue, 31 Jan 2012 18:19:31 +0000
>> > CC: scala-user@...
>> > To: edmondo.porcu@...
>>
>> >
>> > first of all, B <: Int doesn't make sense. Int is a final type, there
>> > cannot be any subtype of Int
>> >
>>
>

Edmondo Porcu | 1 Feb 10:21
Picon

Re: Re: Inferring type of None

Thank you very much, this is what I was looking for :)


Best

2012/2/1 Lars Hupel <hupel-xrfDFxQfymSzQB+pC5nmwQ@public.gmane.org>
Can we please stop using `asInstanceOf` to "let the type inferencer
work"? That's nowhere near a "solution" to your problem.

If you need a `None` which is of type `Option[X]`, use `Option.empty[X]`.



Gmane