【问题标题】:OCaml function typing issueOCaml 函数输入问题
【发布时间】:2013-10-18 09:57:26
【问题描述】:

我正在尝试编写一个 Caml 函数,但在输入时遇到了一些问题。函数是:

let new_game size count gens =
  let rec continueGame board  = function
     0 -> ()
    |n -> drawBoard board size;
          continueGame (nextGeneration board) (n-1)

 in
 continueGame (seedLife (matrix 0 size) count)  (gens) ;;

这里是其他函数的类型:

val drawBoard : int list list -> int -> unit = <fun>
val seedLife : int list list -> int -> int -> int list list = <fun>
val nextGeneration : int list list -> int list list = <fun>
val matrix : 'a -> int -> 'a list list = <fun>

在尝试评估 new_Game 时出现以下错误:

  continueGame (seedLife (matrix 0 size) count)  (gens);;
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 Error: This expression has type int -> int list list
        but is here used with type int list list

为什么会出现这个错误,我该如何解决?

【问题讨论】:

    标签: function functional-programming ocaml caml


    【解决方案1】:

    seedLife 接受 3 个参数,但它只传递了 2 个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多