JuliaLang/julia — Issue #359: const fields for composite types
Author: StefanKarpinski
Created: 2012-02-07 03:24:34+00:00
State: open
Labels: features, speculative

Essentially something like this:

```
type Rational{T<:Integer} <: Real
const num::T
const den::T

function Rational(num::T, den::T)
if num == 0 && den == 0
error("invalid rational: 0//0")
end
g = gcd(den, num)
num = div(num, g)
den = div(den, g)
new(num, den)
end
end
```

A `const` field, like a `const` variable is write-once. In the case of a const field, that means that the value assigned by `new` is the permanent value of the field and it cannot be changed.