Thanks!

I guess this was actually about me not thinking about this the right way 
(perhaps having my metaprogramming notions colored by C++ … *ugh* … and not 
being quite used to the blend of type-based compilation with execution). I 
don't actually need dispatch on this – I just wanted to ensure that types 
got composed correctly – but I see that I can use the same approach as in 
Image <https://github.com/timholy/Images.jl/blob/master/src/core.jl>. That 
is, "explode" the composite type parameter (and extract the component type 
parameters) during constructor execution.

The only thing that I'm sort of missing now is a case where I have *two* 
composite 
type parameters, and I want to make sure one/some of their type parameters 
match. Conceptually, this could be, say, to array types, and I want to make 
sure they have the same number of dimensions, and this should end up as a 
type parameter ("exploded" as before). An example would be if one wanted to 
extend Image to, say, contain two AbstractArrays (image overlay, or 
something?), and they should have the same dimensions. How would I handle 
that in a natural manner?

I see some possibilities:

   1. Don't. Use duck typing and cross your fingers. (Fine by me, I guess. 
   I'm used to Python, after all.)
   2. Simply extract the dimensions and add an @assert to the constructor.
   3. Extract the dimensions from one and use a type assert with the 
   appropriate type parameter on the other (sort of similar).

I just wonder if there is some way to do this with the type system, so that 
it's more compiler-friendly (so it can all ideally be optimized away)?

Reply via email to