Qiyamah
December 18, 2019, 7:20am
1
abstract type Fun{T,R} <: Function end
struct TypedFun{T<:Tuple,R} <: Fun{T,R}
fn::Function
end
function test(fun::Fun{Tuple{T},Vector{CV} where CV<:T}) where T
println(T)
end
function testy(fun::Fun{Tuple{T},Vector{CV} where CV<:T}) where T
:A
end
func = TypedFun{Tuple{Int64},Array{CV,1} where CV<:Int64}(x->[x])
supertype(typeof(func))
Fun{Tuple{Int64},Array{CV,1} where CV<:Int64}
#this works
testy(func)
> :A
#this doesn't work
test(func)
ERROR: UndefVarError: T not defined
why? and how can I fix it?
Thanks
can you provide a constructor for Fun
?
Qiyamah
December 18, 2019, 6:12pm
3
yeah did it in the original post.
the problem i saw was that: Array{CV,1} where CV<:Int64}
is not a type. from slack:
julia> T = Array{A,1} where A<:Int
Array{A,1} where A<:Int64
julia> T.var
A<:Int64
julia> T.var.ub
Int64
1 Like
Qiyamah
December 18, 2019, 7:33pm
5
It is a type it is UnionAll . And in the dispatch it should have bounded with Int.
But it didn’t
1 Like
Syx_Pek
December 18, 2019, 7:41pm
6
Here is a MWE showing the problem I think. I’m not sure what cause it but perhaps someone can explain it to me:
struct F{X} end
f(x::F{Vector{Y} where Y <: X}) where X = println(X)
f(F{Vector{Y} where Y <: Int}()) # errors
1 Like
Is this error related to:
struct test{A,B}
a::A
b::B
end
f = function(x::test{A,B}) where {A,B}
test(x.a, x.b)
end
Results in error: UndefVarError: B not defined
f1 = function(x::test{A,B};) where {A,B}
test(x.a, x.b)
end
But this has no error
1 Like
Welcome to the Julia discourse forum! I am not sure the issue is related to this topic — next time, please open a new discussion.
This looks like a bug, you may want to open an issue .
In the meantime, consider the workaround
f = function(x::test{A,B}) where B where A
test(x.a, x.b)
end
also note that if you are just trying to define a method for f
, not a closure,
function f(x::test{A,B}) where {A,B}
test(x.a, x.b)
end
of course works. Finally, it is common to capitalize type names , eg Test
.
2 Likes