This came up as I was trying to define a sphere manifold type which can 
have distinct metric structures put on it, here is how I have to do it in 
Julia:

abstract Manifold
abstract Metric

immutable Metric1 <: Metric
end

immutable Metric2 <: Metric
end 

immutable Sphere{T<:Metric} <: Manifold
dim::int
end

metric(M::Sphere{Metric1}, x1, x2) = ...
metric(M::Sphere{Metric2}, x1, x2) = ...

As you can see, I have to define a whole other type tree just so my metric 
function can distinguish between sphere manifolds depending on what metric 
structure I want it to have.  It would be both simpler and make more sense 
conceptually to attach the metric to the manifold itself when I instantiate 
it.  Of course you might say I should just define two functions metric1 and 
metric2, but this doesn't really make sense either because these metrics do 
not cut across multiple manifolds, and thus there would be no way to take 
advantage of the multiple dispatch functionality.


Reply via email to