如何在Idris中使用形式参数(值绑定)进行基本模式匹配?

时间:2018-05-30 12:25:40

标签: idris

当我在伊德里斯尝试这个时,

contrived : (List a, Char, (Int, Double), String, Bool) -> Bool
contrived   ([]    ,  'b',  (1,   2.0),   "hi" , True) = False
contrived    (a,  b,  c,   d,  e) = True

我收到错误消息Can't infer argument a to contrived, Can't infer argument a to List, Can't infer argument a to []。但是看看Manning的书,我的方法没有看到任何明显的句法问题。

1 个答案:

答案 0 :(得分:4)

您收到错误消息,因为Idris现在想要在REPL中调用函数时类型Should be Replaced With you domain(或更确切地说是[])。您可以指定这样的隐含信息,如下所示:

a

或者像这样:

contrived {a = Nat} ([],  'b',  (1, 2.0), "hi" , True)
> False

contrived (the (List Nat) [], 'b', (1, 2.0), "hi" , True) > False 计划中不需要:

true