On Wednesday, April 29, 2015 at 9:00:00 PM UTC+10, Robert Gates wrote:
>
> Dear Julia users:
>
> I'm trying to define a parametric composite type with fields whose types 
> depend on both the type parameter as well as the parameter of the type 
> parameter. This is what I tried:
>
> type Foo{T}
>   a::T
> end
>
> type Bar{F <: Foo}
>   a::F
>   b::F.parameters[1]
> end
> ERROR: type TypeVar has no field parameters
>
> type Bar{F <: Foo{T})
>   a::F
>   b::T
> end
> ERROR: UndefVarError: T not defined
>
> Is there any way to achieve what I am trying to do without explicitly 
> parametrizing Bar by T? Explicitly parametrizing would work, however, it 
> feels redundant since T is already contained in Foo.
>
>
In neither case is T defined, in the first case you are using an abstract 
Foo for which no T has been defined. And in the second you are 
parameterising Foo by something undefined which just happens to have the 
same name as the parameter name used in the definition of Foo.

So bar has to be parameterised to provide the parameter to supply to Foo, 
and to use as the field in bar.

But note also that Foo{T} is a composite type, not an abstract type so 
there is no type that F can have that satisfies the subtype constraint 
(except Julia may allow Foo{T} itself, not sure).

Cheers
Lex
 

> Best,
> Robert
>
>
>
>
>
>
>

Reply via email to