Hi,
I would like to use a computed type for a parametrized method definition,
in order to catch as early as possible errors in types. I tried this
abstract typeA
immutable typeA1 <: typeA end
immutable typeA2 <: typeA end
type typeB1 end
type typeB2 end
function transformType(T)
if T == typeA1
return typeB1
elseif T == typeA2
return typeB2
end
error("Cannot handle type $T")
end
function compute{T<:typeA}(a::transformType(T), b::transformType(T))
return (a, b)
end
but it failed with the following error message
ERROR: Cannot handle type T<:typeA
in error at error.jl:21
in transformType at /Users/bpiwowar/Desktop/test.jl:15
in include at
/opt/homebrew-cask/Caskroom/julia/0.3.5/Julia-0.3.5.app/Contents/Resources/julia/lib/julia/sys.dylib
in include_from_node1 at loading.jl:128
in process_options at
/opt/homebrew-cask/Caskroom/julia/0.3.5/Julia-0.3.5.app/Contents/Resources/julia/lib/julia/sys.dylib
in _start at
/opt/homebrew-cask/Caskroom/julia/0.3.5/Julia-0.3.5.app/Contents/Resources/julia/lib/julia/sys.dylib
while loading /Users/bpiwowar/Desktop/test.jl, in expression starting on
line 18
The type transformType(T)is hence computed when the method is defined, but
not when the method is called. Is there any way to prevent this (to defer
evaluation at compilation time?).
The only other way (I can think of) to get this result would be to use
macros and enumerate the different possible types, but if somebody can
think of a better solution, thanks!