- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Why can't a vararg also be a call by name param ?
Tue, 2009-11-24, 15:54
Scalac does not like this mix :
def funk[T](a: =>T*)
Are there any good reason why ?
Cheers
Max
Tue, 2009-11-24, 16:27
#2
Re: Why can't a vararg also be a call by name param ?
On Tue, Nov 24, 2009 at 09:54:04AM -0500, Maxime Lévesque wrote:
> Scalac does not like this mix :
>
> def funk[T](a: =>T*)
>
> Are there any good reason why ?
https://lampsvn.epfl.ch/trac/scala/ticket/237
"Parameters should be allowed as by-name and repeated"
(Opened 2 years ago, so don't hold your breath)
Tue, 2009-11-24, 16:37
#3
Re: Why can't a vararg also be a call by name param ?
2009/11/24 Viktor Klang :
> scala> def f[T](a: (=> T)*) : List[T] = Nil
> :1: error: no by-name parameter type allowed here
> def f[T](a: (=> T)*) : List[T] = Nil
>
> instead of
>
> scala> def f[T](a: => T*) : List[T] = Nil
> :1: error: ')' expected but identifier found.
> def f[T](a: => T*) : List[T] = Nil
I think the second case could be interesting as well... It would have
to be of type Function0[Seq[T]]. The question would be what the exact
semantics of such a call from the view of the call-site would be.
scala> def f[T](a: (=> T)*) : List[T] = Nil
<console>:1: error: no by-name parameter type allowed here
def f[T](a: (=> T)*) : List[T] = Nil
instead of
scala> def f[T](a: => T*) : List[T] = Nil
<console>:1: error: ')' expected but identifier found.
def f[T](a: => T*) : List[T] = Nil
2009/11/24 Maxime Lévesque <maxime.levesque@gmail.com>
--
Viktor Klang
| "A complex system that works is invariably
| found to have evolved from a simple system
| that worked." - John Gall
Blog: klangism.blogspot.com
Twttr: twitter.com/viktorklang
Code: github.com/viktorklang