User loginNavigation |
Higher-order type constructor polymorphism vs./and template style specializationI'm wondering if there are language implementations that (elegantly?) combine what Scala (at least) refers to as "higher-order type constructor polymorphism" with the code specialization capabilities of C++ style templates? I don't mean the notion of "specialization" sometimes used to generically describe how instantiating a template List[int] will (likely) generate new code. I mean programmer driven template specialization. That's pretty much the question, so now I'll make a fool of myself trying to come up with an example. class Vector[T](size:int, init:T) extends Sequence[T] So Iterable, say, has methods like map and friends that will now return Vector[U] for some function (T => U). And all the Iterator and Builder machinery comes out nicely typed. Yada yada yada. Now, it would be *really* nice to somehow be able to implement bit vectors with custom code. Making up a silly keyword: specialize class Vector[Bool](.... We don't really want a vector of 32 bit Bool values! We want some custom bitwise code over an array of bytes or unsigned ints or something. We'll also need specialized Iterators[Vector[Bool]] (hopefully inlined) and associated machinery. But in the end we get a usable bit vector class (1) with much better space/speed for Vector[Bool] and (2) we can still write code like this. def somefun(vi:Vector[Int]): Vector[Bool] = vi.map((_ % 2 == 0)); Just a dumb and obvious example. We could also inquire about method (or function) specializations on values yada yada yada. Hence my question - are there language implementations that nicely combine their elegant type systems with the power of template style code specialization? Sorry if this is too implementation oriented a question. Scott By scottmcl at 2008-06-17 20:32 | LtU Forum | previous forum topic | next forum topic | other blogs | 6374 reads
|
Browse archives
Active forum topics |
Recent comments
27 weeks 2 days ago
27 weeks 2 days ago
27 weeks 2 days ago
49 weeks 3 days ago
1 year 1 week ago
1 year 3 weeks ago
1 year 3 weeks ago
1 year 5 weeks ago
1 year 10 weeks ago
1 year 10 weeks ago