On Wednesday, June 11, 2014 09:34:52 AM Florian Oswald wrote:
> type MySubType <: MyAbstract
> field1 :: ASCIIString
> function MySubType(x)
> new(x)
> end
> end
I would strongly recommend getting rid of the inner constructor. It doesn't do
anything that the default one doesn't do, and you've just caused Julia to skip
creating an outer constructor for you. In most code, inner constructors are
relatively rare and should be provided only if you have a specific need for
them.
> Myt(10,MySubType)
> ERROR: type: Myt: in T, expected T<:MyAbstract, got Type{DataType}
The interpretation of that error is the following: you're passing z, which you
declare must be an object for which isa(z, MyAbstract) is true. But
isa(MySubType, MyAbstract) is false. You need to pass an instance (e.g.,
MySubType("hi")) rather than the type itself.
Once you realize that z must be an instance of type T, you'll quickly realize
that your z("hi") in the inner constructor of Myt is another error. It should
just be z.
As John says, the alternative is to delcare the Myt inner constructor as
Myt(n,z::Type{T}) and then try to build it as you did. But I doubt that will
give you what you want.
--Tim