3

最小限の例で私の問題を説明します。次の 3 つのファイルがあるとします。

A.jl

module A

export Atype, f

type Atype  
end

f = function(x::Atype)
    println("f called with A")
end
end #module

B.jl

module B

export Btype, f

type Btype  
end

f = function(x::Btype)
    println("f called with B")
end
end #module

Main.jl

 using A
 using B

 main = function()
    x = Atype()
    f(x)
 end

 main()

ここでは、f関数の 2 つのバージョンがあります。複数のディスパッチの考え方を正しく理解していれば、実行時にどのバージョンを使用すべきかを差し引く必要があります。したがって、Main.jl を実行するとf called with A. 残念ながら、私は得る

$ julia Main.jl 
ERROR: type: anonymous: in typeassert, expected Btype, got Atype
 in include at /usr/bin/../lib64/julia/sys.so
 in process_options at /usr/bin/../lib64/julia/sys.so
 in _start at /usr/bin/../lib64/julia/sys.so
while loading /home/grzes/julia_sucks/Main.jl, in expression starting on line 9

コメントアウトするusing Bと、正常に動作します。明らかにf、B.jl から A.jl を上書きfしました。

では、問題は次のとおりです。問題はどこにあるのでしょうか。私のアプローチまたは使用する Julia のバージョン (0.3.7) では? どうすればこれを回避できますか?

完全修飾名 (例: ) に置き換えusing Aて使用することは、適切な解決策ではないことに注意してください。これは、複数のディスパッチの要点と矛盾します。コンパイル時に、またはを使用する必要があるかどうかわかりません。import AA.fA.fB.f

4

1 に答える 1