Julia: Instantiated type parameters -
how 1 define type that, array, has concrete/instantiated type parameter? initial instinct this:
immutable foo{n::integer} data::array{float64, n} end however, generates following error:
error: syntax: malformed type parameter list
the following code acceptable:
immutable foo{n} data::array{float64, n} end foo{1}([1,2,3]) foo{1}([1.0,2.0,3.0])
but i've been unable find instructions on restricting type of parameter n. realize in case may not strictly necessary, surely provide more intuitive error messages , should possible?
edit:
i've found partial solution so:
immutable bar{n} data::array{int64, n} bar(dat) = ( typeof(n) <: integer && n > 0 ? new(dat) : error("bar parameter n must positive integer")) end bar{1}([1,2,3]) bar{1}([1,2,3])
bar{0}([]) error: bar parameter n must positive integer
while solves problem @ hand, still interested in knowing if there's way specify type parameter's instantiated type front tried in initial code fragment in post?
it not possible restrict type parameters this, though there has been discussion allow syntax tried @ top. believe solution came of checking type parameter in inner constructor considered best practice right now.
Comments
Post a Comment