partially applied classes

View: New views
4 Messages — Rating Filter:   Alert me  

partially applied classes

by Kubitz, Jörg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

I am just reading about partially applied functions. So I wonder if there are partially applied classes too?

 

Scala compiles

 

class Complex(real: Double, imag: Double){

  //…

}

class Real(real: Double) extends Complex(real,0){}

 

But when I create an instance of Real my first guess is that the JVM would reserve Space for the private imag as well. Right or wrong? Does the Scala compiler replace the private member by a static final constant?


Re: partially applied classes

by Ricky Clarkson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> So I wonder if there
> are partially applied classes too?

Nope.

> But when I create an instance of Real my first guess is that the JVM would
> reserve Space for the private imag as well. Right or wrong?

Right.

> Does the Scala
> compiler replace the private member by a static final constant?

Nope.  That would mean compiling two versions of all the code in
Complex, one using the constant and one using the private member.
That would break separate compilation.

--
Ricky Clarkson
Java and Scala Programmer, AD Holdings
+44 1565 770804
Skype: ricky_clarkson
Google Talk: ricky.clarkson@...
Google Wave: ricky.clarkson@...

Parent Message unknown Re: partially applied classes

by Ricky Clarkson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Why would you need such a feature?

2009/11/6 Kubitz, Jörg <jkubitz@...>:

> Thanks for the fast reply.
>
> What a pitty. I would need such a feature.
>
> The following compiles:
>
>
>
> trait tComplex{
>
>   def real:Double
>
>   def imag:Double
>
>
>
> }
>
>
>
> trait tReal{
>
>   def value:Double
>
>
>
> }
>
>
>
> class Complex(r: Double, i: Double) extends tComplex{
>
>   def real:Double=r
>
>   def imag:Double=i
>
> }
>
>
>
> class Real(value: Double) extends tComplex {
>
>   def real:Double=value
>
>   def imag:Double=0
>
> }
>
>
>
> But that looks complicated. And I don’t know wheter “Traits” introduce
> runtime overhead which could result in poor Performance. Do they?
>
> Plus: This way a Real “is” not a Complex L
>
>
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Ricky Clarkson [mailto:ricky.clarkson@...]
> Gesendet: Freitag, 6. November 2009 12:43
> An: Kubitz, Jörg
> Cc: Scala Users
> Betreff: Re: [scala-user] partially applied classes
>
>
>
>> So I wonder if there
>
>> are partially applied classes too?
>
>
>
> Nope.
>
>
>
>> But when I create an instance of Real my first guess is that the JVM would
>
>> reserve Space for the private imag as well. Right or wrong?
>
>
>
> Right.
>
>
>
>> Does the Scala
>
>> compiler replace the private member by a static final constant?
>
>
>
> Nope.  That would mean compiling two versions of all the code in
>
> Complex, one using the constant and one using the private member.
>
> That would break separate compilation.
>
>
>
> --
>
> Ricky Clarkson
>
> Java and Scala Programmer, AD Holdings
>
> +44 1565 770804
>
> Skype: ricky_clarkson
>
> Google Talk: ricky.clarkson@...
>
> Google Wave: ricky.clarkson@...



--
Ricky Clarkson
Java and Scala Programmer, AD Holdings
+44 1565 770804
Skype: ricky_clarkson
Google Talk: ricky.clarkson@...
Google Wave: ricky.clarkson@...

Re: partially applied classes

by Ismael Juma :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 2009-11-06 at 11:42 +0000, Ricky Clarkson wrote:
> > But when I create an instance of Real my first guess is that the JVM would
> > reserve Space for the private imag as well. Right or wrong?
>
> Right.

Actually there is not enough information in the example to say so. imag
could simply be a constructor parameter depending on what happens inside
the body of Complex.

Best,
Ismael