the short answer is: you can't do that
the slightly longer answer is: make a unique type name for each and
add functions that map from year to the form and vice versa. macros
can be handy for this:
macro tax_year(year, typ)
typ.head == :type || error("bad type")
typename = esc(typ.args[2])
typ = esc(typ)
year = year::Int
quote
$typ
form_for_year_map[$year] = $typename
end
end
form_for_year_map = Dict{Int, TaxForm}
form_for_year(year) = form_for_year_map[year]
@tax_year 2010 type TaxForm82B <: TaxForm
a
b
end
On Tue, Mar 25, 2014 at 10:50 PM, Glen Hertz <[email protected]> wrote:
> Hi,
>
> Perhaps I'm doing this the wrong way but I wanted to parameterize some types
> by a constant, Year, like so:
>
> abstract TaxForm{Year}
>
>
> type Form1{2013} <: TaxForm{2013}
> a
> b
> c
> Form1{2013}() = new(0.0, 0.0, 0.0)
> end
>
>
> type Form1{2012} <: TaxForm{2012}
> a
> b
> # no C field
> Form1{2013}() = new(0.0, 0.0, 0.0)
> end
>
>
> type Form2{2013} <: TaxForm{2013}
> e
> f
> g
> Form2{2013}() = new(0.0, 0.0, 0.0)
> end
>
>
> type Form2{2012} <: TaxForm{2012}
> e2 # different fields this year
> f2
> g2
> Form2{2012}() = new(0.0, 0.0, 0.0)
> end
>
>
> # Create all tax form for a given year:
> createforms(Year::Int) = {Form1{Year}(), Form2{Year}()}
>
> tax_payable(f::Form1{2013}) = max(2*f.a, 0.0) + max(f.b, 0.0) +
> max(0.95*f.c, 0.0)
> tax_payable(f::Form1{2012}) = max(3*f.a, 0.0) + max(f.b, 0.0)
>
> tax_payable(f::Form2{2013}) = max(f.e, 0.0) + max(f.f, 0.0) + max(0.91*f.g,
> 0.0)
> tax_payable(f::Form2{2012}) = max(e2.a, 0.0) + max(f.f2, 0.0) +
> max(0.93*f.g2, 0.0)
>
> The fields of the form are different from form to form, and the same form
> can change year to year. I've tried quite a few combinations and I get
> syntax errors.
>
> Any recommendations how to code something like this?
>
> Yes, it is Tax time....
>
> Glen