Thanks Jiahao, that was an interesting read. Could your `istypeclosed`
function not use `Base.return_types(f, Ts)` instead of parsing
`code_typed`?
And now a bit of self-promotion: I recently thought about uses of
Base.return_types when implementing traits/interfaces in
https://github.com/mauro3/Traits.jl . After reading this I got round to
implement using return types as well. So now with Traits.jl you can
define a trait for a (mathematical) group:
```
julia> using Traits
julia> @traitdef Group{X,Y} begin # a trait defining a group
@constraints begin
X==Y
end
*(X,Y) -> X
*(X,Y,X) -> X
one(X) -> X
inv(X) -> X
end
julia> istrait(Group{Int,Int}, verbose=true)
Method `inv` with signature ((Int64,),(Int64,)) has wrong return type: (Float64,)
false
julia> istrait(Group{Array{Float64,2}, Array{Float64,2}}, verbose=true) # should be true though!
Method `inv` with signature ((Array{Float64,2},),(Array{Float64,2},)) has wrong return type: (Any,)
false
julia> istrait(Group{Float64, Float64})
true
julia> @traitfn f{X; Group{X,X}}(x::X, y::X) = inv(x*y*y)
f (generic function with 4 methods)
julia> f(5,6)
ERROR: TraitException("No matching trait found for function f")
in traitdispatch at /home/mauro/.julia/v0.4/Traits/src/traitfns.jl:252
in f at /home/mauro/.julia/v0.4/Traits/src/traitfns.jl:333
julia> f(5.,6.)
0.005555555555555556
```
Mauro