Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

@traitdef in one module, @traitimpl in another module #31

Open
bjmtrk opened this issue Jan 10, 2016 · 1 comment
Open

@traitdef in one module, @traitimpl in another module #31

bjmtrk opened this issue Jan 10, 2016 · 1 comment

Comments

@bjmtrk
Copy link

bjmtrk commented Jan 10, 2016

Hi,

i was trying to do this, but obviously i get the following issue:

julia> module X
        using Traits
        export TR
        @traitdef TR{T} begin
            fun(T) -> Number
        end
       end
  This warning is ok:
WARNING: Method definition func_for_method(Method, Any, Any) in module Inference at inference.jl:610 overwritten in module Traits at /local/rra/HEJU/julia_pkg/Traits.jl/src/base_fixes.jl:8.
WARNING: Method definition eltype(Type{Base.Associative{#K<:Any, #V<:Any}}) in module Base at dict.jl:240 overwritten in module Traits at /local/rra/HEJU/julia_pkg/Traits.jl/src/base_fixes.jl:20.
  endof ok-warnings.
X

julia> module Y
           using Traits
           using X
           @traitimpl TR{Int64} begin
               fun(x::Int64) = 3x
           end
       end
**** Checking X.TR{T}: Could not instantiate instance for type encoding the trait X.TR{Int64}.
This usually indicates that something is amiss with the @traitdef
or that one of the generic functions is not defined.
The error was: UndefVarError(:fun)
ERROR: AssertionError: istrait(TR{Int64},verbose=true)

How can i do this?
Thanks

(Edited by @mauro3: added tripple back-ticks. Also note that with quoting macro I meant enclosing them with back-ticks and not just a single back-tick in front of them.)

@mauro3
Copy link
Owner

mauro3 commented Jan 11, 2016

It should work, but doesn't... This workaround works:

julia> module X
       using Traits
       export TR
       fun(x)= 1
       @traitdef TR{T} begin
           fun(T) -> Number
       end
       end
X

julia> module Y
       using Traits
       using X
       @traitimpl TR{Int64} begin
           fun(x::Int64) = 3x
       end
       end

Maybe an explicit function def should be used? Like so:

julia> module X
       using Traits
       export TR
       function fun end # not sure whether an explicit function-def 
       @traitdef TR{T} begin
           fun(T) -> Number
       end
       end

But this does not work either. However, in light of JuliaLang/julia#14636, I'm not sure how to implement this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants