this is a good solution, although it prevents the user from defining their own custom metric.
On Monday, January 18, 2016 at 9:33:05 AM UTC-8, Matt Bauman wrote: > > On Monday, January 18, 2016 at 11:54:49 AM UTC-5, Anonymous wrote: >> >> 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. >> > > Here's another alternative: > > @enum Metric RIEMANNIAN LORENTZIAN # ... > immutable Sphere > dim::Int > metric::Metric > end > function metric(s::Sphere) > if s.metric == RIEMANNIAN > # … > elseif s.metric == LORENTZIAN #… > end > end > > The key point is that you don't always need to attach a function — you can > attach data that describes the object's properties, and then use that in > your external functions. > > (This is crossposted at > http://stackoverflow.com/questions/34841635/immutable-type-with-function-fields-in-julia > ) >
