I'm looking at a compiler written for a extremely pared down version of C. I'm new to ocaml, and am particularly confused about this structure
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. I didn't post the entire file (it's very long) and my question is just about the outermost let statement.
I've always only seen simple let statements where you might have something like
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?
Would be perhaps more clearly written as:
That extra space makes it more apparent that
nameis a function which takes one argument. That argument is a tuple of two valuesparam1andparam2. It is locally bound only for the expression(param1, expr1 param2)which does not use thisnamefunction.The
param1andparam2names are not used in the expressionexpr1(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.Effectively
namedoes nothing at all.