Awesome
CanonicalTraits
Check documentations for more details.
Features
- Zero-cost abstractions(via
@implement!
) - Multiple-param traits
- Functional dependencies
- Implemented via dictionay passing algorithm
- Elegant notations
- Flexible Instances & Flexible Classes
"""vector space to scalar space"""
function V2F end
@trait VecSpace{F, V} where
{F = V2F(V)} begin
vec_add :: [V, V] => V
scalar_mul :: [F, V] => V
end
@trait VecSpace{F, V} >: InnerProd{F, V} where
{F = V2F(V)} begin
dot :: [V, V] => F
end
@trait InnerProd{F, V} >: Ortho{F, V} where
{F = V2F(V)} begin
gram_schmidt! :: [V, Vector{V}] => V
gram_schmidt!(v :: V, vs :: Vector{V}) where V = begin
for other in vs
coef = dot(v, other) / dot(other, other)
incr = scalar_mul(-coef, other)
v = vec_add(v, incr)
end
magnitude = sqrt(dot(v, v))
scalar_mul(1/magnitude, v)
end
end