compiler-errors - 为什么编译器说明我要应用许多参数?

标签 compiler-errors ocaml

对于此函数,我得到了两个整数,并且应该将数字范围从num1到num2放入列表中。

let rec range num1 num2 =
  (* YOUR CODE HERE *)
  if num2 < num1 then raise IncorrectRange
  else if num1 = num2 then [num1]
  else let num3 = num1 +1 in num1::(range num3 num2)

let range() = assert (range 2 5 = [2;3;4;5])

由于某种原因,当我测试我的代码时,它指出该函数的类型为unit-> unit,并且应用了太多的参数。我究竟做错了什么?

最佳答案

您的代码由不同类型的名为range的函数的两个定义组成。这是合法的OCaml代码(第二个定义隐藏了第一个),但这似乎不太可能达到预期的目的。

我的猜测是assert行中有一个错字。

无论如何,您在此之后输入的任何代码都将使用range的第二个定义,该定义的类型实际上为unit -> unit

关于compiler-errors - 为什么编译器说明我要应用许多参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60269561/

相关文章:

visual-c++ - 错误 C2143 VC++12

c++11 #include <thread> 给出编译错误

function - OCaml - 给出类型为 (int -> int) -> int 的函数

file - 在 OCaml 的父目录中创建文件?

debugging - 何时应使用 -g 在 OCaml 中打印堆栈跟踪?

f# - 有人拥有或知道 F# 中可用的持久前缀特里树吗?

c# - 签署 winforms exe 时出现加密失败 - "The Parameter is incorrect"

iphone - 在iPhone而非iPhone模拟器上编译时出错

c - Flex 中 '(' 标记之前的预期标识符或 '{'

constructor - 使用只有一个元组值的变体类型构造函数