mauro3 / Traits.jl

Exploration of traits in Julia
Other
39 stars 6 forks source link

Callable trait? #16

Closed malmaud closed 9 years ago

malmaud commented 9 years ago

I love this package!

I was wondering if it would make sense to have a common trait corresponding to whether a type T is 'callable', in the sense that if isa(x, T) then x(args...) will work.

mauro3 commented 9 years ago

Tnx! Yes, that does make sense. To be callable this should work:

@traitdef IsCallable{X} begin
    @constraints begin
        X==Function || length(methods(call, (A,)))>0
    end
end

or are there other cases?

malmaud commented 9 years ago

I think that should do it.

mauro3 commented 9 years ago

Cool, I'll probably put that into https://github.com/mauro3/SimpleTraits.jl/blob/master/src/base-traits.jl. The idea is that Traits.jl is built on top of SimpleTraits.jl.

mauro3 commented 9 years ago

Closed in favor of https://github.com/mauro3/SimpleTraits.jl/issues/1