【问题标题】:right-hand-side of clause doesn't agree with funct result sml子句右侧与函数结果 sml 不一致
【发布时间】:2012-05-31 15:07:16
【问题描述】:
fun can_move    0 0 0 nil = false
|   can_move    limit_down V 0 a  = true
|   can_move    limit_down V count a =  if  ((V-limit_down)>hd a) then false else               can_move limit_down V (count-1) tl a ;

嘿,这是我的代码,我只想检查值 V-limit_down 是否低于 int 列表 a 中的数字。我想从 a 列表中检查的参数数量是 V/10 。例如,如果我有 20 V,那么我想检查列表的前两个参数。为什么会出现这个错误?

can_move.sml:1.6-3.114 Error:right-hand-side of clause doesn't agree with function     result type
[tycon mismatch] 
expression: int -> int -> int list -> bool
result type: int -> int -> (Z' list -> 'Z list) -> int list -> bool
in declaration:

can_move (fn arg =) (fn <pat> => <exp>))

【问题讨论】:

    标签: sml smlnj


    【解决方案1】:

    您似乎忘记了模式匹配最后右侧的括号。在递归调用can_move limit_down V (count-1) tl a 中,请注意您的最后一个参数是tl a。通常,解析器可以确定这是一个函数应用程序。不幸的是,当应用程序的结果是另一个应用程序的一部分时,这是不明确的,就像这里一样。

    解决方法是将调用括起来:can_move limit_down V (count-1) (tl a)

    【讨论】:

    • 没那么蠢。我无法弄清楚括号小姐,多亏了​​你的问题,我现在解决了。 @MikEKOU
    猜你喜欢
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 2014-05-02
    • 2021-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多