- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
R: Re: Overcome type erasures with manifest.
Mon, 2012-01-23, 12:56
Is there anything like an HMap? Not an hashmap :)
------Messaggio originale------
Da: Miles Sabin
A:Kevin Wright
Cc:Edmondo
Cc:Dennis Haupt
Cc:scala-user@googlegroups.com
Oggetto: Re: [scala-user] Overcome type erasures with manifest.
Inviato: 23 Gen 2012 12:52
On Mon, Jan 23, 2012 at 11:46 AM, Kevin Wright wrote:
> Try this one on for size: https://github.com/milessabin/shapeless
With the proviso that shapeless is highly experimental ;-)
Sample REPL session ...
scala> import shapeless._ ; import Nat._
import shapeless._
import Nat._
scala> trait A[T]
defined trait A
scala> class B extends A[Int] ; class C extends A[Long] ; class E
extends A[Double]
defined class B
defined class C
defined class E
scala> val l = new B :: new C :: new E :: HNil
l: shapeless.::[B,shapeless.::[C,shapeless.::[E,shapeless.HNil]]] =
B@1d333c99 :: C@ecf6fc9 :: E@54b3fcb7 :: HNil
scala> l(_0)
res0: B = B@1d333c99
scala> l(_1)
res1: C = C@ecf6fc9
scala> l(_2)
res2: E = E@54b3fcb7
scala> l.toList[A[_]]
res3: List[A[_]] = List(B@1d333c99, C@ecf6fc9, E@54b3fcb7)
Cheers,
Miles
Mon, 2012-01-23, 13:41
#2
Re: R: Re: Overcome type erasures with manifest.
yes. it's called "class".
do you want groovy/ruby like extensible classes, just with type safety?
-------- Original-Nachricht --------
> Datum: Mon, 23 Jan 2012 11:56:41 +0000
> Von: edmondo.porcu@gmail.com
> An: "Miles Sabin" , "Kevin Wright"
> CC: "Dennis Haupt" , scala-user@googlegroups.com
> Betreff: R: Re: [scala-user] Overcome type erasures with manifest.
> Is there anything like an HMap? Not an hashmap :)
> ------Messaggio originale------
> Da: Miles Sabin
> A:Kevin Wright
> Cc:Edmondo
> Cc:Dennis Haupt
> Cc:scala-user@googlegroups.com
> Oggetto: Re: [scala-user] Overcome type erasures with manifest.
> Inviato: 23 Gen 2012 12:52
>
> On Mon, Jan 23, 2012 at 11:46 AM, Kevin Wright
> wrote:
> > Try this one on for size: https://github.com/milessabin/shapeless
>
> With the proviso that shapeless is highly experimental ;-)
>
> Sample REPL session ...
>
> scala> import shapeless._ ; import Nat._
> import shapeless._
> import Nat._
>
> scala> trait A[T]
> defined trait A
>
> scala> class B extends A[Int] ; class C extends A[Long] ; class E
> extends A[Double]
> defined class B
> defined class C
> defined class E
>
> scala> val l = new B :: new C :: new E :: HNil
> l: shapeless.::[B,shapeless.::[C,shapeless.::[E,shapeless.HNil]]] =
> B@1d333c99 :: C@ecf6fc9 :: E@54b3fcb7 :: HNil
>
> scala> l(_0)
> res0: B = B@1d333c99
>
> scala> l(_1)
> res1: C = C@ecf6fc9
>
> scala> l(_2)
> res2: E = E@54b3fcb7
>
> scala> l.toList[A[_]]
> res3: List[A[_]] = List(B@1d333c99, C@ecf6fc9, E@54b3fcb7)
>
> Cheers,
>
>
> Miles
>
Mon, 2012-01-23, 16:21
#3
Re: R: Re: Overcome type erasures with manifest.
Groovy beans would be rather convenient compared to case classes,
black boxes that they are (in regard to reflection)
Perhaps in 2.10 new Scala reflection will allow for straight forward,
non-external library dependent, access to class property names & types
at run time.
Then you could do something useful, like validate servlet params map
against the properties of a to-be-created case class instance without
having to resort to Scalaz or other doctorate-required library to act
as a proxy for creating your objects.
Sure you lose compile time safety, but then again, your application
and its domain classes have become so much easier to work with. Pick
your poison.
Take with a grain of salt, just a couple of months into Scala, coming
from Groovy, where run time freedom creates its own basket of
"joy" (typos, untraceable errors, no generics, etc.)
On Jan 23, 1:33 pm, "Dennis Haupt" wrote:
> yes. it's called "class".
> do you want groovy/ruby like extensible classes, just with type safety?
>
> -------- Original-Nachricht --------
>
>
>
>
>
>
>
> > Datum: Mon, 23 Jan 2012 11:56:41 +0000
> > Von: edmondo.po...@gmail.com
> > An: "Miles Sabin" , "Kevin Wright"
> > CC: "Dennis Haupt" , scala-user@googlegroups.com
> > Betreff: R: Re: [scala-user] Overcome type erasures with manifest.
> > Is there anything like an HMap? Not an hashmap :)
> > ------Messaggio originale------
> > Da: Miles Sabin
> > A:Kevin Wright
> > Cc:Edmondo
> > Cc:Dennis Haupt
> > Cc:scala-user@googlegroups.com
> > Oggetto: Re: [scala-user] Overcome type erasures with manifest.
> > Inviato: 23 Gen 2012 12:52
>
> > On Mon, Jan 23, 2012 at 11:46 AM, Kevin Wright
> > wrote:
> > > Try this one on for size: https://github.com/milessabin/shapeless
>
> > With the proviso that shapeless is highly experimental ;-)
>
> > Sample REPL session ...
>
> > scala> import shapeless._ ; import Nat._
> > import shapeless._
> > import Nat._
>
> > scala> trait A[T]
> > defined trait A
>
> > scala> class B extends A[Int] ; class C extends A[Long] ; class E
> > extends A[Double]
> > defined class B
> > defined class C
> > defined class E
>
> > scala> val l = new B :: new C :: new E :: HNil
> > l: shapeless.::[B,shapeless.::[C,shapeless.::[E,shapeless.HNil]]] =
> > B@1d333c99 :: C@ecf6fc9 :: E@54b3fcb7 :: HNil
>
> > scala> l(_0)
> > res0: B = B@1d333c99
>
> > scala> l(_1)
> > res1: C = C@ecf6fc9
>
> > scala> l(_2)
> > res2: E = E@54b3fcb7
>
> > scala> l.toList[A[_]]
> > res3: List[A[_]] = List(B@1d333c99, C@ecf6fc9, E@54b3fcb7)
>
> > Cheers,
>
> > Miles
>
> > --
> > Miles Sabin
> > tel: +44 7813 944 528
> > gtalk: mi...@milessabin.com
> > skype: milessabin
> > g+:http://www.milessabin.com
> >http://twitter.com/milessabin
> >http://www.chuusai.com/
>
> > Inviato da BlackBerry(R) Wireless Handheld
On Mon, Jan 23, 2012 at 11:56 AM, wrote:
> Is there anything like an HMap? Not an hashmap :)
You mean something like this?
http://goo.gl/P96YT
Cheers,
Miles