Re: [julia-users] Circular parametric types
This is now https://github.com/JuliaLang/julia/issues/14825 On Wednesday, January 27, 2016 at 4:52:00 PM UTC+1, Yichao Yu wrote: > > On Wed, Jan 27, 2016 at 10:35 AM, Tommy Hofmann> wrote: > > I am trying to define two parametric types with circular dependency as > > follows. > > > > abstract abstest > > > > type t1{A <: abstest, B} > > x::A > > y::B > > end > > > > type t2{C, B} <: abstest > > x::C > > y::t1{t2{C, B}, B} > > end > > > > Unfortunately it doesn't work: > > ERROR: TypeError: t1: in A, expected A<:abstest, got Type{t2{C,B}} > > > > Apparently he is complaining about the definition of field y in the > > definition of type t2. But t2{C, B} is a subtype of abstest, so {t2{C, > B}, > > B} should be valid parameters for type t1. Probably I am missing > something > > here. > > Looks like a bug to me. You should probably open an issue about this. > > > > > Thanks, > > Tommy > > > > >
Re: [julia-users] Circular parametric types
On Thursday, January 28, 2016 at 12:23:34 PM UTC+1, Toivo Henningsson wrote: > > Yes, you're right! I guess that you would have to break the chain at some > point with Any or similar, which doesn't feel quite satisfying. But maybe > it's the best that you can do for now. > > In your code, when you access fields that are not typed as strictly as you > want, at least you can put in a type assertion on the value to allow the > compiler to specialise on the correct type. > I did a similar thing before with the type assertions. I was trying to clean it up and make it more compiler friendly, and this was the problem I ran into.
Re: [julia-users] Circular parametric types
In the meantime, you can relax the second type definition to type t2{C, T} <: abstest x::C y::T end which will allow you to construct all the parametric types that you want, plus some more. You could add a check in the t2 constructor to make sure that T meets your expectations.
Re: [julia-users] Circular parametric types
On Thursday, January 28, 2016 at 10:57:59 AM UTC+1, Toivo Henningsson wrote: > > In the meantime, you can relax the second type definition to > > type t2{C, T} <: abstest > x::C > y::T > end > > which will allow you to construct all the parametric types that you want, > plus some more. You could add a check in the t2 constructor to make sure > that T meets your expectations. > I am not sure this will work, since in my case T would in this case "be" t1{t2{C, T},B}, which again contains T and which results in an infinite recursion? I don't know how to construct a concrete instance of this type in this case.
Re: [julia-users] Circular parametric types
Yes, you're right! I guess that you would have to break the chain at some point with Any or similar, which doesn't feel quite satisfying. But maybe it's the best that you can do for now. In your code, when you access fields that are not typed as strictly as you want, at least you can put in a type assertion on the value to allow the compiler to specialise on the correct type.
Re: [julia-users] Circular parametric types
Are circular type trees supposed to work? We can't even join types: *abstract A* *abstract B* *type D <: Union{A, B} # Fail* *end*
Re: [julia-users] Circular parametric types
*typealias D Union{A,B}* *julia> **D <: Union{A,B}* *true* *;) thanks*
Re: [julia-users] Circular parametric types
Whoops. Can I get editing permission for my own posts?
Re: [julia-users] Circular parametric types
"even" On Wed, Jan 27, 2016 at 8:43 PM, Bryan Riverawrote: > Are circular type trees supposed to work? > > We can't even join types: > > *abstract A* > > *abstract B* > > *type D <: Union{A, B} # Fail* > > *end* >
Re: [julia-users] Circular parametric types
*typealias D Union{A,B}* *julia> **D <: Union{A,B}* *true* *Is this what you meant?* *So if the example code is a bug, does this mean Julia should have a recursive type tree?*
Re: [julia-users] Circular parametric types
On Wed, Jan 27, 2016 at 10:35 AM, Tommy Hofmannwrote: > I am trying to define two parametric types with circular dependency as > follows. > > abstract abstest > > type t1{A <: abstest, B} > x::A > y::B > end > > type t2{C, B} <: abstest > x::C > y::t1{t2{C, B}, B} > end > > Unfortunately it doesn't work: > ERROR: TypeError: t1: in A, expected A<:abstest, got Type{t2{C,B}} > > Apparently he is complaining about the definition of field y in the > definition of type t2. But t2{C, B} is a subtype of abstest, so {t2{C, B}, > B} should be valid parameters for type t1. Probably I am missing something > here. Looks like a bug to me. You should probably open an issue about this. > > Thanks, > Tommy > >