Skip to content

mind6/Inherit.jl

Repository files navigation

Build Status Coverage

Inherit.jl

Inherit.jl provides macros for inheriting fields and interface declarations from a supertype. The macros generate native Julia types so you can work with familiar syntax while ensuring that required methods are implemented.

Quick start

using Inherit

@abstractbase struct Fruit
    weight::Float64
    function cost(fruit::Fruit, unitprice::Float64) end
end

@implement struct Apple <: Fruit
    coresize::Int
end

function cost(apple::Apple, unitprice::Float64)
    apple.weight * unitprice * (apple.coresize < 5 ? 2.0 : 1.0)
end

println(cost(Apple(3.0, 4), 1.0))
# output
6.0

Further resources:

About

Inherit fields and method interfaces in Julia

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages