---------- Forwarded message ----------
From:
Brian Maso <brian....@gmail.com>
Date: Wed, Nov 2, 2011 at 2:02 PM
Subject: Re: [scala-user] List of classes with types
To: Konstantine Kougios <
kostas....@googlemail.com>
Essentially what you are doing is using List as a Tuple of arbitrary arity. If you would really like to preserve the type info of the collection at runtime you should take a look at HList and KList, which Mark Harrah has implemented in his github project "up". Using these, you can create "heterogenous lists" -- lists which preserve each element's type information.
You'll not be getting a good heterogenous list "map" implementation, though. If you think about it, application of a single mapping function to different elements of a heterogenous list doesn't make a lot of sense. The map's body would have to be a big switch statement, where each case would pattern match on the element's type. That is, you'd have to squeeze each of the HList elements of types T1, T2, T3, etc. in to the input parameter of the same map function -- you'd lose the type information, since the type of the input parameter would have a lower-bound equal to the least upper bound of the types T1, T2, T3, etc. So even if you preserved type information in an HList, you'd have to throw it away specifically during the invocation of the "map" function.
Brian Maso