在签名中找不到带有约束的实现
Can't find implementation with constraint in signature
我有一个接口依赖于另一个接口,具有一些依赖类型,我无法让编译器在相关函数中约束类型
import Data.Vect
interface Distribution (0 event : Nat) (dist : Nat -> Nat -> Type) where
data Gaussian : Nat -> Nat -> Type where
Distribution e Gaussian where
interface Distribution targets marginal =>
Model (targets : Nat) (marginal : Nat -> Nat -> Type) model where
marginalise : model -> Vect s Double -> marginal targets s
foo : m -> Model 1 Gaussian m => Vect s Double -> Nat
foo model x = let marginal = marginalise model x in ?rhs
我明白了
While processing right hand side of foo. Can't find an implementation for Model ?targets ?marginal m.
foo model x = let marginal = marginalise model x in ?rhs
^^^^^^^^^^^^^^^^^^^
怎么会这样?
如果我使用 marginalise {marginal=Gaussian} {targets=1} model x
它会进行类型检查,但我不明白为什么类型签名尚未确定。
我不认为我问过同样的区域适用于这里
我开始将其作为评论来写,并在中途意识到它可以作为一个完整的答案。
Model 1 Gaussan m
意味着您有 Model
接口的实现,其中有 targets = 1
、marginal = Gaussian
和 model = m
。然后,marginal
的 let 绑定需要 Model a b m
,即 Model
的实现,其中 targets = a
、marginal = b
和 model = m
。但是没有要求 a = 1
和 b = Gaussian
!
我的猜测是,一旦你阅读 determining parameters,你会发现你想要这样的东西:
interface Distribution targets marginal =>
Model (targets : Nat) (marginal : Nat -> Nat -> Type) model | model where
我有一个接口依赖于另一个接口,具有一些依赖类型,我无法让编译器在相关函数中约束类型
import Data.Vect
interface Distribution (0 event : Nat) (dist : Nat -> Nat -> Type) where
data Gaussian : Nat -> Nat -> Type where
Distribution e Gaussian where
interface Distribution targets marginal =>
Model (targets : Nat) (marginal : Nat -> Nat -> Type) model where
marginalise : model -> Vect s Double -> marginal targets s
foo : m -> Model 1 Gaussian m => Vect s Double -> Nat
foo model x = let marginal = marginalise model x in ?rhs
我明白了
While processing right hand side of foo. Can't find an implementation for Model ?targets ?marginal m.
foo model x = let marginal = marginalise model x in ?rhs
^^^^^^^^^^^^^^^^^^^
怎么会这样?
如果我使用 marginalise {marginal=Gaussian} {targets=1} model x
它会进行类型检查,但我不明白为什么类型签名尚未确定。
我不认为
我开始将其作为评论来写,并在中途意识到它可以作为一个完整的答案。
Model 1 Gaussan m
意味着您有 Model
接口的实现,其中有 targets = 1
、marginal = Gaussian
和 model = m
。然后,marginal
的 let 绑定需要 Model a b m
,即 Model
的实现,其中 targets = a
、marginal = b
和 model = m
。但是没有要求 a = 1
和 b = Gaussian
!
我的猜测是,一旦你阅读 determining parameters,你会发现你想要这样的东西:
interface Distribution targets marginal =>
Model (targets : Nat) (marginal : Nat -> Nat -> Type) model | model where