Skip to content

mindbound/ConcreteAbstractions.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ConcreteAbstractions

Build Status

Simulate OOP inheritance while using a (superior) Julia abstract type. Fields and parameters of the "base type" are automatically inserted into the type definition of a "child type". The "base type" is really an abstract type, but we store the internals of the type definition for later injection into the child definition.

This package exports two macros: @base and @extend. The purpose and usage is hopefully well understood from the example below.

Install with:

Pkg.clone("https://github.com/tbreloff/ConcreteAbstractions.jl")
using ConcreteAbstractions

The abstract definition:

@base type AbstractFoo{T}
    a
    b::Int
    c::T
    d::Vector{T}
end

is really more like:

abstract AbstractFoo
ConcreteAbstractions._base_types[:AbstractFoo] = ([:T], :(begin; a; b::Int; c::T; d::Vector{T}; end))

and the child definition:

@extend type Foo <: AbstractFoo
    e::T
end

is really more like:

type Foo{T} <: AbstractFoo
    a
    b::Int
    c::T
    d::Vector{T}
    e::T
end

About

Concrete type inheritance for Julia

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Julia 100.0%