尝试将隐式参数带入Idris定义左侧的范围内,导致“是否将f应用于太多参数”错误

时间:2018-09-24 21:33:52

标签: idris

函数applyRule应该提取类型为n的隐式参数VVect,该隐式参数用在它获得的另一个参数中。

data IVect : Vect n ix -> (ix -> Type) -> Type where -- n is here
  Nil  : IVect Nil b
  (::) : b i -> IVect is b -> IVect (i :: is) b

VVect : Vect n Nat -> Type -> Type -- also here
VVect is a = IVect is (flip Vect a)

-- just for completeness
data Expression = Sigma Nat Expression

applyRule : (signals : VVect is Double) ->
            (params : List Double) ->
            (sigmas : List Double) ->
            (rule : Expression) ->
            Double

applyRule {n} signals params sigmas (Sigma k expr1) = cast n

在不引用{n}的情况下,代码进行类型检查(如果cast n更改为某个有效的double值)。但是,添加它会导致以下错误:

When checking left hand side of applyRule:
Type mismatch between
        Double (Type of applyRule signals params sigmas rule)
and
        _ -> _ (Is applyRule signals
                             params
                             sigmas
                             rule applied to too many arguments?)

这对我来说似乎没有意义,因为我没有对可能依赖于n的任何参数进行模式匹配,因此我认为只需将其放在花括号中即可进入范围。

1 个答案:

答案 0 :(得分:3)

如果data = ['build999.100', 'build999.0', 'buil998.100', 'build997.100', 'build996.100', 'build996.0'] d = {s.split('.')[0]: s for s in data} out = list(d.values()) 在某个地方定义(例如,作为参数中的变量),则只能将其带入范围。否则,很难弄清n的来源-至少对于人类而言。

n