Skip to content

Instantly share code, notes, and snippets.

@avsm
Created August 12, 2009 10:26
Show Gist options
  • Save avsm/166441 to your computer and use it in GitHub Desktop.
Save avsm/166441 to your computer and use it in GitHub Desktop.
(* defines the Ast.binding for a function of form:
let fun_name ?(opt_arg1) ?(opt_arg2) final_ident = function_body ...
XXX: figure out the quotation magic for this, if such exists
*)
let function_with_label_args _loc ~fun_name ~final_ident ~function_body ~return_type opt_args =
let opt_args = opt_args @ [ <:patt< $lid:final_ident$ >> ] in
let rec fn _loc = function
|hd::tl ->
Ast.ExFun(_loc,
Ast.McArr(_loc,
hd,
(Ast.ExNil _loc),
(fn _loc tl)
)
)
|[] -> <:expr< ( $function_body$ : $return_type$ ) >>
in
Ast.BiEq (_loc,
<:patt< $lid:fun_name$ >>,
(fn _loc opt_args)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment