简体   繁体   English

“let name(param1, param2) =..”在 ocaml 中是什么意思(而不是 let name =...)?

[英]What does "let name(param1, param2) = .." mean in ocaml (as opposed to just let name = ...)?

I'm looking at a compiler written for a extremely pared down version of C.我正在查看为 C 的极其精简版本编写的编译器。 I'm new to ocaml, and am particularly confused about this structure我是 ocaml 的新手,对这种结构特别困惑

let check (globals, functions) =
(* A bunch of stuff abstracted out *)
  let check_function ...
   .... (*A b bunch of stuff abstracted out*)
in (globals, List.map check_function functions)

Where globals is a list of (var_type, var_name) and functions is a function records.其中 globals 是 (var_type, var_name) 的列表,functions 是 function 记录。 I didn't post the entire file (it's very long) and my question is just about the outermost let statement.我没有发布整个文件(它很长),我的问题只是关于最外面的 let 语句。

I've always only seen simple let statements where you might have something like我一直只看到简单的 let 语句,你可能有类似的东西

let name = expr1 in expr2

So what does it mean when you have那么当你有时是什么意思

let name(param1, param2) = expr1 in (param1, expr1 param2) 

Kind of similar to what I have here?有点像我这里的?

let name(param1, param2) = expr1 in (param1, expr1 param2)

Would be perhaps more clearly written as:可能会更清楚地写成:

let name (param1, param2) = 
  expr1 
in 
  (param1, expr1 param2)

That extra space makes it more apparent that name is a function which takes one argument.额外的空间使name更明显的是 function ,它接受一个参数。 That argument is a tuple of two values param1 and param2 .该参数是两个值param1param2的元组。 It is locally bound only for the expression (param1, expr1 param2) which does not use this name function.它仅对不使用此name function 的表达式(param1, expr1 param2)进行本地绑定。

The param1 and param2 names are not used in the expression expr1 (they might as well be (_, _) ) and are out of scope when we get to the expression (param1, expr1 param2) so if this is valid code, they refer to bindings from before the code you've shown us.表达式expr1中没有使用param1param2名称(它们也可能是(_, _) ,并且当我们到达表达式(param1, expr1 param2)时,它们不在 scope 中,所以如果这是有效代码,它们指的是到您向我们展示的代码之前的绑定。

Effectively name does nothing at all.实际上, name根本没有任何作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM