自动推理参数类型

时间:2018-02-22 13:11:29

标签: julia

我正在使用下面的代码,似乎Julia应该能够自己推断出类型参数,但事实并非如此。任何想法,也许我做错了什么?

abstract type ABS{A,B} end

struct MyStruct{A,B,K<:ABS{A,B}}
    a::A
    b::B
    MyStruct{A,B,K}(a::A,b::B) where {A,B,K<:ABS{A,B}} = new(a,b)
end

MyStruct{Int64,Float64,ABS{Int64,Float64}}(1,2.1) # <<-- works
MyStruct(1,2.1) # <<-- doesn't work

1 个答案:

答案 0 :(得分:1)

我忘了外部构造函数,正如@gnimuc指出的那样。此代码有效:

Theorem appplied_constructor': forall e1 e2 e, eval (add e1 e2) e ->
                                      (eval e2 e /\ e1 = lit 0) \/
                                      (~e1 = lit 0 /\
                                        exists n1 n2, eval e1 n1 /\
                                                 eval e2 n2 /\
                                                 n1 + n2 = e).
Proof.
  intros.
  inversion H; subst; eauto 10.
Qed.