OCaml警告说明
我一直在阅读,不确定其中一些是什么意思(没有提供示例)。具体而言,我想了解: 触发以下警告的代码示例(我认为我对每个警告的含义的解释与实际含义不同,因为我发现很难生成触发非直接语言错误的警告的案例): “祖先变量”和“扩展构造函数”是什么: 这意味着什么:OCaml警告说明,ocaml,Ocaml,我一直在阅读,不确定其中一些是什么意思(没有提供示例)。具体而言,我想了解: 触发以下警告的代码示例(我认为我对每个警告的含义的解释与实际含义不同,因为我发现很难生成触发非直接语言错误的警告的案例): “祖先变量”和“扩展构造函数”是什么: 这意味着什么: 61. Unboxable type in primitive declaration 62. Type constraint on GADT type declaration 下面是警告5的示例: # let f a b = a + b;
61. Unboxable type in primitive declaration
62. Type constraint on GADT type declaration
下面是警告5的示例:
# let f a b = a + b;;
val f : int -> int -> int = <fun>
# ignore (f 3);;
Warning 5: this function application is partial,
maybe some arguments are missing.
- : unit = ()
#设f a b=a+b;;
val f:int->int->int=
#忽略(f3);;
警告5:此功能应用程序是部分的,
也许缺少一些论据。
-:单位=()
默认情况下禁用警告6。如果启用它,则很容易生成:
$ rlwrap ocaml -w +6
OCaml version 4.06.1
# let f ~a = a * 10;;
val f : a:int -> int = <fun>
# f 3;;
Warning 6: label a was omitted in the application of this function.
- : int = 30
$rlwrap-ocaml-w+6
OCaml版本4.06.1
#设f~a=a*10;;
val f:a:int->int=
#f3;;
警告6:应用此功能时忽略了标签a。
-:int=30
其余的都超出了我在不查看编译器源代码的情况下所能理解的范围。也许会有一两位专家来为他们举例。要完成列表:
type t = A
let f x = match x with A _ -> 0
class c = object end
class d = object
inherit c as super
end
exn
module M:sig end = struct
type exn += Unused
end
type t = I of int [@@unboxed]
type t = I of int
external id: t -> t = "%identity"
警告61:此基元声明使用类型t,该类型未加注释且
不可折叠的。此类类型的表示形式将来可能会发生变化
版本。应该用[@@boxed]注释t的声明
或[@@unbox]
type 'a t =
| A: 'a -> float t
| B of 'a
constraint 'a = float
B[]
是错误,而A[]
是正常的
我认为,每一个警告的一个例子都是非常有价值的资源。但我怀疑其中很多都是技术性的,很难理解。关于28:So
val f:t->int=
不是人们所期望的那样吗?function
关键字只与一个参数一起工作,这与28没有特别的关系:让零默认值=函数一些n->n | None->0
哦,当然,我忘了。自从我上次写Ocaml已经有一段时间了。。。感谢您的澄清编辑。伟大的解释!没有参数的构造函数可以在模式匹配中使用通配符参数,这有点令人惊讶。我真的很喜欢Dune现在把所有警告都变成错误的默认设置!
type t = I of int
external id: t -> t = "%identity"
type 'a t =
| A: 'a -> float t
| B of 'a
constraint 'a = float