Quantcast

What's the difference between ClassManifest and Manifest?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

What's the difference between ClassManifest and Manifest?

Heiko Seeberger-4
Hi,

could someone please explain the difference between ClassManifest and Manifest? And when to use which one?

Thanks,

Heiko

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the difference between ClassManifest and Manifest?

Jorge Ortiz
My understand is that if:

  type T = Foo[Bar[Baz]]

then Manifest[T] represents the entire Foo[Bar[Baz]] type, whereas ClassManifest[T] only represents Foo[_].

For instantiating Arrays, you only need to know whether it's a primitive array or a reference array, so only the ClassManifest is needed. (But a Manifest is also a ClassManifest...)

--j

On Tue, May 4, 2010 at 12:44 AM, Heiko Seeberger <[hidden email]> wrote:
Hi,

could someone please explain the difference between ClassManifest and Manifest? And when to use which one?

Thanks,

Heiko

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the difference between ClassManifest and Manifest?

Arjan Blokzijl
That's what I understood from the Array SID as well, and the code also seemed to indicate this. However, a brief experiment in the REPL showed this:

scala> class Foo[T]
defined class Foo

scala> class Bar[T]
defined class Bar

scala> class Baz
defined class Baz

scala> type T = Foo[Bar[Baz]] 
defined type alias T

scala>val m = manifest[T]
m: Manifest[T] = Foo[Bar[Baz]]

scala> val cm = classManifest[T]
cm: ClassManifest[T] = Foo[Bar[Baz]]

scala> m.typeArguments
res0: List[scala.reflect.Manifest[_]] = List(Bar[Baz])

scala> cm.typeArguments
res1: List[scala.reflect.OptManifest[_]] = List(Bar[Baz])

scala> cm == m
res2: Boolean = true

scala> cm.isInstanceOf[Manifest[_]]
res3: Boolean = false

scala> m.isInstanceOf[Manifest[_]] 
res4: Boolean = true

scala> cm.isInstanceOf[ClassManifest[_]]
res5: Boolean = true


Perhaps I'm doing the completely wrong experiment here, but at first sight the ClassManifest also seems to contain all type arguments.


Arjan


On Tue, May 4, 2010 at 7:13 PM, Jorge Ortiz <[hidden email]> wrote:
My understand is that if:

  type T = Foo[Bar[Baz]]

then Manifest[T] represents the entire Foo[Bar[Baz]] type, whereas ClassManifest[T] only represents Foo[_].

For instantiating Arrays, you only need to know whether it's a primitive array or a reference array, so only the ClassManifest is needed. (But a Manifest is also a ClassManifest...)

--j

On Tue, May 4, 2010 at 12:44 AM, Heiko Seeberger <[hidden email]> wrote:
Hi,

could someone please explain the difference between ClassManifest and Manifest? And when to use which one?

Thanks,

Heiko

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the difference between ClassManifest and Manifest?

Jorge Ortiz
Yes, you're correct. I see now that ClassManifest captures as much type information as it can.

The difference comes here:

scala> class Foo[T]
defined class Foo

scala> type T = Foo[_]
defined type alias T

scala> val m = manifest[T]
<console>:6: error: could not find implicit value for parameter m: Manifest[T]
       val m = manifest[T]
                       ^

scala> val m = classManifest[T]
m: ClassManifest[T] = Foo[<?>]

In this case, you can make a ClassManifest[T], but you can't make a Manifest[T].

--j

On Tue, May 4, 2010 at 10:19 PM, Arjan Blokzijl <[hidden email]> wrote:
That's what I understood from the Array SID as well, and the code also seemed to indicate this. However, a brief experiment in the REPL showed this:

scala> class Foo[T]
defined class Foo

scala> class Bar[T]
defined class Bar

scala> class Baz
defined class Baz

scala> type T = Foo[Bar[Baz]] 
defined type alias T

scala>val m = manifest[T]
m: Manifest[T] = Foo[Bar[Baz]]

scala> val cm = classManifest[T]
cm: ClassManifest[T] = Foo[Bar[Baz]]

scala> m.typeArguments
res0: List[scala.reflect.Manifest[_]] = List(Bar[Baz])

scala> cm.typeArguments
res1: List[scala.reflect.OptManifest[_]] = List(Bar[Baz])

scala> cm == m
res2: Boolean = true

scala> cm.isInstanceOf[Manifest[_]]
res3: Boolean = false

scala> m.isInstanceOf[Manifest[_]] 
res4: Boolean = true

scala> cm.isInstanceOf[ClassManifest[_]]
res5: Boolean = true


Perhaps I'm doing the completely wrong experiment here, but at first sight the ClassManifest also seems to contain all type arguments.


Arjan


On Tue, May 4, 2010 at 7:13 PM, Jorge Ortiz <[hidden email]> wrote:
My understand is that if:

  type T = Foo[Bar[Baz]]

then Manifest[T] represents the entire Foo[Bar[Baz]] type, whereas ClassManifest[T] only represents Foo[_].

For instantiating Arrays, you only need to know whether it's a primitive array or a reference array, so only the ClassManifest is needed. (But a Manifest is also a ClassManifest...)

--j

On Tue, May 4, 2010 at 12:44 AM, Heiko Seeberger <[hidden email]> wrote:
Hi,

could someone please explain the difference between ClassManifest and Manifest? And when to use which one?

Thanks,

Heiko

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the difference between ClassManifest and Manifest?

Jorge Ortiz
Huh. I have NO idea.

--j

On Wed, May 5, 2010 at 12:13 AM, Heiko Seeberger <[hidden email]> wrote:
Interesting stuff!

Why does this work when using Foo[_] does not?

scala> manifest[Option[_]]
res9: scala.reflect.Manifest[Option[_]] = scala.Option[Any]

Heiko

On 5 May 2010 08:29, Jorge Ortiz <[hidden email]> wrote:
Yes, you're correct. I see now that ClassManifest captures as much type information as it can.

The difference comes here:

scala> class Foo[T]
defined class Foo

scala> type T = Foo[_]
defined type alias T

scala> val m = manifest[T]
<console>:6: error: could not find implicit value for parameter m: Manifest[T]
       val m = manifest[T]
                       ^

scala> val m = classManifest[T]
m: ClassManifest[T] = Foo[<?>]

In this case, you can make a ClassManifest[T], but you can't make a Manifest[T].

--j

On Tue, May 4, 2010 at 10:19 PM, Arjan Blokzijl <[hidden email]> wrote:
That's what I understood from the Array SID as well, and the code also seemed to indicate this. However, a brief experiment in the REPL showed this:

scala> class Foo[T]
defined class Foo

scala> class Bar[T]
defined class Bar

scala> class Baz
defined class Baz

scala> type T = Foo[Bar[Baz]] 
defined type alias T

scala>val m = manifest[T]
m: Manifest[T] = Foo[Bar[Baz]]

scala> val cm = classManifest[T]
cm: ClassManifest[T] = Foo[Bar[Baz]]

scala> m.typeArguments
res0: List[scala.reflect.Manifest[_]] = List(Bar[Baz])

scala> cm.typeArguments
res1: List[scala.reflect.OptManifest[_]] = List(Bar[Baz])

scala> cm == m
res2: Boolean = true

scala> cm.isInstanceOf[Manifest[_]]
res3: Boolean = false

scala> m.isInstanceOf[Manifest[_]] 
res4: Boolean = true

scala> cm.isInstanceOf[ClassManifest[_]]
res5: Boolean = true


Perhaps I'm doing the completely wrong experiment here, but at first sight the ClassManifest also seems to contain all type arguments.


Arjan


On Tue, May 4, 2010 at 7:13 PM, Jorge Ortiz <[hidden email]> wrote:
My understand is that if:

  type T = Foo[Bar[Baz]]

then Manifest[T] represents the entire Foo[Bar[Baz]] type, whereas ClassManifest[T] only represents Foo[_].

For instantiating Arrays, you only need to know whether it's a primitive array or a reference array, so only the ClassManifest is needed. (But a Manifest is also a ClassManifest...)

--j

On Tue, May 4, 2010 at 12:44 AM, Heiko Seeberger <[hidden email]> wrote:
Hi,

could someone please explain the difference between ClassManifest and Manifest? And when to use which one?

Thanks,

Heiko

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org






--
Heiko Seeberger


Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the difference between ClassManifest and Manifest?

√iktor Ҡlang


On Wed, May 5, 2010 at 9:30 AM, Jorge Ortiz <[hidden email]> wrote:
Huh. I have NO idea.


REPL voodoo?
 
--j

On Wed, May 5, 2010 at 12:13 AM, Heiko Seeberger <[hidden email]> wrote:
Interesting stuff!

Why does this work when using Foo[_] does not?

scala> manifest[Option[_]]
res9: scala.reflect.Manifest[Option[_]] = scala.Option[Any]

Heiko

On 5 May 2010 08:29, Jorge Ortiz <[hidden email]> wrote:
Yes, you're correct. I see now that ClassManifest captures as much type information as it can.

The difference comes here:

scala> class Foo[T]
defined class Foo

scala> type T = Foo[_]
defined type alias T

scala> val m = manifest[T]
<console>:6: error: could not find implicit value for parameter m: Manifest[T]
       val m = manifest[T]
                       ^

scala> val m = classManifest[T]
m: ClassManifest[T] = Foo[<?>]

In this case, you can make a ClassManifest[T], but you can't make a Manifest[T].

--j

On Tue, May 4, 2010 at 10:19 PM, Arjan Blokzijl <[hidden email]> wrote:
That's what I understood from the Array SID as well, and the code also seemed to indicate this. However, a brief experiment in the REPL showed this:

scala> class Foo[T]
defined class Foo

scala> class Bar[T]
defined class Bar

scala> class Baz
defined class Baz

scala> type T = Foo[Bar[Baz]] 
defined type alias T

scala>val m = manifest[T]
m: Manifest[T] = Foo[Bar[Baz]]

scala> val cm = classManifest[T]
cm: ClassManifest[T] = Foo[Bar[Baz]]

scala> m.typeArguments
res0: List[scala.reflect.Manifest[_]] = List(Bar[Baz])

scala> cm.typeArguments
res1: List[scala.reflect.OptManifest[_]] = List(Bar[Baz])

scala> cm == m
res2: Boolean = true

scala> cm.isInstanceOf[Manifest[_]]
res3: Boolean = false

scala> m.isInstanceOf[Manifest[_]] 
res4: Boolean = true

scala> cm.isInstanceOf[ClassManifest[_]]
res5: Boolean = true


Perhaps I'm doing the completely wrong experiment here, but at first sight the ClassManifest also seems to contain all type arguments.


Arjan


On Tue, May 4, 2010 at 7:13 PM, Jorge Ortiz <[hidden email]> wrote:
My understand is that if:

  type T = Foo[Bar[Baz]]

then Manifest[T] represents the entire Foo[Bar[Baz]] type, whereas ClassManifest[T] only represents Foo[_].

For instantiating Arrays, you only need to know whether it's a primitive array or a reference array, so only the ClassManifest is needed. (But a Manifest is also a ClassManifest...)

--j

On Tue, May 4, 2010 at 12:44 AM, Heiko Seeberger <[hidden email]> wrote:
Hi,

could someone please explain the difference between ClassManifest and Manifest? And when to use which one?

Thanks,

Heiko

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org






--
Heiko Seeberger


Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org




--
Viktor Klang
| "A complex system that works is invariably
| found to have evolved from a simple system
| that worked." - John Gall

Akka - the Actor Kernel: Akkasource.org
Twttr: twitter.com/viktorklang
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the difference between ClassManifest and Manifest?

Jason Zaugg
The difference between Foo and List is variance in the type parameter.
Type inference and implicit search work differently in these cases,
although I'm haven't got my head around the details.

scala> class Foo[+A]
defined class Foo

scala> manifest[Foo[_]]
res0: scala.reflect.Manifest[Foo[_]] = Foo[Any]

scala> class Foo[A]
defined class Foo

scala> manifest[Foo[_]]
<console>:6: error: could not find implicit value for parameter m:
Manifest[Foo[_]]
       manifest[Foo[_]]
               ^

I think the real difference is to do with primitive vs reference
types, but I can't figure it out by glancing through the sources.

-jason

On Wed, May 5, 2010 at 9:35 AM, Viktor Klang <[hidden email]> wrote:

>
>
> On Wed, May 5, 2010 at 9:30 AM, Jorge Ortiz <[hidden email]> wrote:
>>
>> Huh. I have NO idea.
>
> REPL voodoo?
>
>>
>> --j
>>
>> On Wed, May 5, 2010 at 12:13 AM, Heiko Seeberger
>> <[hidden email]> wrote:
>>>
>>> Interesting stuff!
>>> Why does this work when using Foo[_] does not?
>>> scala> manifest[Option[_]]
>>> res9: scala.reflect.Manifest[Option[_]] = scala.Option[Any]
>>> Heiko
>>> On 5 May 2010 08:29, Jorge Ortiz <[hidden email]> wrote:
>>>>
>>>> Yes, you're correct. I see now that ClassManifest captures as much type
>>>> information as it can.
>>>> The difference comes here:
>>>> scala> class Foo[T]
>>>> defined class Foo
>>>> scala> type T = Foo[_]
>>>> defined type alias T
>>>> scala> val m = manifest[T]
>>>> <console>:6: error: could not find implicit value for parameter m:
>>>> Manifest[T]
>>>>        val m = manifest[T]
>>>>                        ^
>>>> scala> val m = classManifest[T]
>>>> m: ClassManifest[T] = Foo[<?>]
>>>> In this case, you can make a ClassManifest[T], but you can't make a
>>>> Manifest[T].
>>>> --j
>>>> On Tue, May 4, 2010 at 10:19 PM, Arjan Blokzijl
>>>> <[hidden email]> wrote:
>>>>>
>>>>> That's what I understood from the Array SID as well, and the code also
>>>>> seemed to indicate this. However, a brief experiment in the REPL showed
>>>>> this:
>>>>> scala> class Foo[T]
>>>>> defined class Foo
>>>>> scala> class Bar[T]
>>>>> defined class Bar
>>>>> scala> class Baz
>>>>> defined class Baz
>>>>> scala> type T = Foo[Bar[Baz]]
>>>>> defined type alias T
>>>>> scala>val m = manifest[T]
>>>>> m: Manifest[T] = Foo[Bar[Baz]]
>>>>> scala> val cm = classManifest[T]
>>>>> cm: ClassManifest[T] = Foo[Bar[Baz]]
>>>>> scala> m.typeArguments
>>>>> res0: List[scala.reflect.Manifest[_]] = List(Bar[Baz])
>>>>> scala> cm.typeArguments
>>>>> res1: List[scala.reflect.OptManifest[_]] = List(Bar[Baz])
>>>>> scala> cm == m
>>>>> res2: Boolean = true
>>>>> scala> cm.isInstanceOf[Manifest[_]]
>>>>> res3: Boolean = false
>>>>> scala> m.isInstanceOf[Manifest[_]]
>>>>> res4: Boolean = true
>>>>> scala> cm.isInstanceOf[ClassManifest[_]]
>>>>> res5: Boolean = true
>>>>>
>>>>> Perhaps I'm doing the completely wrong experiment here, but at first
>>>>> sight the ClassManifest also seems to contain all type arguments.
>>>>>
>>>>> Arjan
>>>>>
>>>>> On Tue, May 4, 2010 at 7:13 PM, Jorge Ortiz <[hidden email]>
>>>>> wrote:
>>>>>>
>>>>>> My understand is that if:
>>>>>>   type T = Foo[Bar[Baz]]
>>>>>> then Manifest[T] represents the entire Foo[Bar[Baz]] type, whereas
>>>>>> ClassManifest[T] only represents Foo[_].
>>>>>> For instantiating Arrays, you only need to know whether it's a
>>>>>> primitive array or a reference array, so only the ClassManifest is needed.
>>>>>> (But a Manifest is also a ClassManifest...)
>>>>>> --j
>>>>>> On Tue, May 4, 2010 at 12:44 AM, Heiko Seeberger
>>>>>> <[hidden email]> wrote:
>>>>>>>
>>>>>>> Hi,
>>>>>>> could someone please explain the difference between ClassManifest and
>>>>>>> Manifest? And when to use which one?
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Heiko
>>>>>>>
>>>>>>> Company: weiglewilczek.com
>>>>>>> Blog: heikoseeberger.name
>>>>>>> Follow me: twitter.com/hseeberger
>>>>>>> OSGi on Scala: scalamodules.org
>>>>>>> Lift, the simply functional web framework: liftweb.net
>>>>>>> Stambecco, highly scalable computing: stambecco.org
>>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Heiko Seeberger
>>>
>>> Company: weiglewilczek.com
>>> Blog: heikoseeberger.name
>>> Follow me: twitter.com/hseeberger
>>> OSGi on Scala: scalamodules.org
>>> Lift, the simply functional web framework: liftweb.net
>>> Stambecco, highly scalable computing: stambecco.org
>>
>
>
>
> --
> Viktor Klang
> | "A complex system that works is invariably
> | found to have evolved from a simple system
> | that worked." - John Gall
>
> Akka - the Actor Kernel: Akkasource.org
> Twttr: twitter.com/viktorklang
>
Loading...