Ast_helper.Exp(3)

πŸ’– Ast_helper.Exp β€” the manual, but make it cute πŸ’–

Hiii bestie πŸ’… so this page lives in the OCaml library manual and it's called Ast_helper.Exp(3). It's all about Expressions β€” like, the whole thing. Every function here is a little helper that builds you a Parsetree expression-shaped thing out of its ingredients. It's giving "AST construction, but make it ergonomic." πŸ¦‹


✨ NAME ✨

Ast_helper.Exp β€” Expressions ✨

No cap, that's the whole name section. Short king. πŸ‘‘


πŸŽ€ MODULE πŸŽ€

The module is literally:

Module Ast_helper.Exp

Yeah. That's it. It is itself. Main character energy. 🌈


πŸ’œ DOCUMENTATION πŸ’œ

🌸 Module Exp 🌸

Module Exp
 : sig end

So it's a module named Exp whose signature is sig end β€” the docs are just showing you the module shape and then moving on, because the good stuff is inside. Keep scrolling, bestie 😭

🫢 Expressions 🫢

Okay so here's the tea β˜• β€” every single one of these bad boys takes these two optional lil cuties first:

  • ?loc:Ast_helper.loc
  • ?attrs:Ast_helper.attrs

That's the shared uniform, iykyk. Then the actual arguments come after, and you get a Parsetree.expression back at the end. Let's go through them one by one, no skipping, I promise πŸ’―


  • mk β€” takes a Parsetree.expression_desc, hands you back a Parsetree.expression. The blueprint-to-building pipeline. πŸ—οΈ
val mk : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression_desc -> Parsetree.expression
  • attr β€” this one's different, bestie! It takes the expression first and there are no ?loc/?attrs here β€” it's Parsetree.expression -> Parsetree.attribute -> Parsetree.expression. Two positional args, no optional drama. πŸ™ˆ
val attr : Parsetree.expression -> Parsetree.attribute ->
       Parsetree.expression
  • ident β€” give it an Ast_helper.lid and you get an expression. Ident-ity crisis? Never heard of her. πŸͺž
val ident : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Ast_helper.lid -> Parsetree.expression
  • constant β€” an Ast_helper.lid's calm cousin. You feed it a Parsetree.constant, it gives you an expression. Consistent. Reliable. Slay. πŸ“
val constant : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.constant -> Parsetree.expression
  • let_ β€” yes with the underscore, that's not a typo πŸ‘€. An Asttypes.rec_flag, a Parsetree.value_binding list, and an expression walk in; an expression walks out.
val let_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Asttypes.rec_flag -> Parsetree.value_binding list ->
       Parsetree.expression -> Parsetree.expression
  • function_ β€” underscore again, we love a keyword-dodging queen πŸ‘‘. Takes a Parsetree.function_param list, a Parsetree.type_constraint option, and a Parsetree.function_body.
val function_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.function_param list -> Parsetree.type_constraint option ->
       Parsetree.function_body -> Parsetree.expression
  • apply β€” the application one. An expression plus a (Asttypes.arg_label * Parsetree.expression) list and boom, expression. It's giving "you had one job and you applied yourself." πŸ’…
val apply : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> (Asttypes.arg_label * Parsetree.expression) list
       -> Parsetree.expression
  • match_ β€” trailing underscore, she's shy 🫣. An expression and a Parsetree.case list go in, an expression comes out.
val match_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Parsetree.case list -> Parsetree.expression
  • try_ β€” same shape as her sister match_, also rocking the underscore. Expression + Parsetree.case list β†’ expression. Try her, she's flawless ✨
val try_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Parsetree.case list -> Parsetree.expression
  • tuple β€” a (string option * Parsetree.expression) list in, an expression out. Note the string option in there, that's real and I'm not making it up πŸ”₯
val tuple : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs -> (string
       option * Parsetree.expression) list -> Parsetree.expression
  • construct β€” an Ast_helper.lid plus a Parsetree.expression option, and you get an expression. Construction project: complete βœ…
val construct : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Ast_helper.lid -> Parsetree.expression option -> Parsetree.expression
  • variant β€” an Asttypes.label and a Parsetree.expression option walk in. Variant hours, who's she πŸ¦‹
val variant : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Asttypes.label -> Parsetree.expression option -> Parsetree.expression
  • record β€” a (Ast_helper.lid * Parsetree.expression) list and a Parsetree.expression option at the end, then out pops an expression. Two-part situation, stay with me πŸ“
val record : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       (Ast_helper.lid * Parsetree.expression) list -> Parsetree.expression
       option -> Parsetree.expression
  • field β€” expression, then Ast_helper.lid, then expression. Order matters, don't @ me πŸ™ƒ
val field : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Ast_helper.lid -> Parsetree.expression
  • setfield β€” three positional besties: expression, Ast_helper.lid, expression. (Yes, that's what's written. Yes, it's a lot. Yes, it's iconic.) πŸ”₯
val setfield : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Ast_helper.lid -> Parsetree.expression ->
       Parsetree.expression
  • array β€” a Parsetree.expression list goes in, one expression comes out. Many become one. Girl group energy. 🎀
val array : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression list -> Parsetree.expression
  • ifthenelse β€” expression, expression, then a Parsetree.expression option (that's your else branch being optional, nudge nudge), then expression. πŸ‘€
val ifthenelse : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Parsetree.expression -> Parsetree.expression
       option -> Parsetree.expression
  • sequence β€” expression, expression, expression. Two in, one out. Do them in order, bestie ➑️
val sequence : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Parsetree.expression -> Parsetree.expression
  • while_ β€” underscore, obviously πŸ’…. Two expressions in, one expression out.
val while_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Parsetree.expression -> Parsetree.expression
  • for_ β€” the long one, buckle up 🎒. Parsetree.pattern, then two expressions, then an Asttypes.direction_flag, then another expression. Five positional arguments, all accounted for, none of them optional.
val for_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.pattern -> Parsetree.expression -> Parsetree.expression ->
       Asttypes.direction_flag -> Parsetree.expression -> Parsetree.expression
  • coerce β€” an expression, a Parsetree.core_type option, and a Parsetree.core_type. Glow-up transformation arc ✨
val coerce : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Parsetree.core_type option ->
       Parsetree.core_type -> Parsetree.expression
  • constraint_ β€” underscore gang πŸ”ͺ. An expression and a Parsetree.core_type.
val constraint_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Parsetree.core_type -> Parsetree.expression
  • send β€” an expression and an Ast_helper.str. Sending it, fr fr πŸ“¨
val send : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Ast_helper.str -> Parsetree.expression
  • new_ β€” underscore because new was taken πŸ˜”. Just an Ast_helper.lid, that's the whole meal.
val new_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Ast_helper.lid -> Parsetree.expression
  • setinstvar β€” Ast_helper.str first, then an expression. Note the order, it's not the same as field up there πŸ‘€
val setinstvar : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Ast_helper.str -> Parsetree.expression -> Parsetree.expression
  • override β€” a (Ast_helper.str * Parsetree.expression) list. Just the one listy arg. Simple, clean, ate πŸ’…
val override : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       (Ast_helper.str * Parsetree.expression) list -> Parsetree.expression
  • assert_ β€” underscore, she's asserting herself πŸ’β€β™€οΈ. One expression in, one out.
val assert_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Parsetree.expression
  • lazy_ β€” underscore AND lazy. Truly the mood. One expression in, one out. 😴
val lazy_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Parsetree.expression
  • poly β€” an expression plus a Parsetree.core_type option, out comes an expression. Polymorphic and proud 🌈
val poly : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.expression -> Parsetree.core_type option ->
       Parsetree.expression
  • object_ β€” underscore, and it takes a Parsetree.class_structure. Object-oriented moment, we stan πŸŽ€
val object_ : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.class_structure -> Parsetree.expression
  • newtype β€” an Ast_helper.str and an expression, then expression. Fresh type, fresh me πŸ’«
val newtype : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Ast_helper.str -> Parsetree.expression -> Parsetree.expression
  • pack β€” a Parsetree.module_expr plus a Parsetree.package_type option. Pack it up, pack it in 🧳
val pack : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.module_expr -> Parsetree.package_type option ->
       Parsetree.expression
  • letop β€” a Parsetree.binding_op, then a Parsetree.binding_op list, then an expression. Let-operators said "we're here too" πŸ”₯
val letop : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.binding_op -> Parsetree.binding_op list ->
       Parsetree.expression -> Parsetree.expression
  • extension β€” takes a Parsetree.extension. Extension representation, periodt. ⭐
val extension : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.extension -> Parsetree.expression
  • unreachable β€” takes literally unit (so (), the emptiest queen alive) and gives you an expression. Haunting. πŸ’€
val unreachable : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs -> unit
       -> Parsetree.expression
  • struct_item β€” a Parsetree.structure_item and a Parsetree.expression go in, one expression comes out. Structure, but make it an expression πŸ›οΈ
val struct_item : ?loc:Ast_helper.loc -> ?attrs:Ast_helper.attrs ->
       Parsetree.structure_item -> Parsetree.expression -> Parsetree.expression
  • case β€” ⚠️ heads up bestie, this one plays by its own rules: no ?loc, no ?attrs, and it returns a Parsetree.case, not an expression. It's Parsetree.pattern, then ?guard:Parsetree.expression (a named optional β€” note the label!), then Parsetree.expression.
val case : Parsetree.pattern -> ?guard:Parsetree.expression ->
       Parsetree.expression -> Parsetree.case
  • binding_op β€” also a rebel 🫣. No ?loc/?attrs, and the return type is Parsetree.binding_op. Order is: Ast_helper.str, Parsetree.pattern, Parsetree.expression, then Ast_helper.loc last, not optional, no question mark.
val binding_op : Ast_helper.str -> Parsetree.pattern ->
       Parsetree.expression -> Ast_helper.loc -> Parsetree.binding_op

πŸ’‘ Friendly reminder from your girl: attr, case, and binding_op are the three that don't do the ?loc/?attrs thing, and case + binding_op give you back Parsetree.case / Parsetree.binding_op instead of an expression. Don't get caught out, iykyk 🫢

🌟 Sign-off 🌟

That's the whole page, bestie β€” no crumbs left, no options skipped, every signature exactly where it belongs πŸ’–βœ¨πŸŽ€

This little masterpiece was brought to you by OCamldoc, dated 2026-06-22, living at Ast_helper.Exp(3). Like, she's documented, she's dated, she's iconic. Periodt. πŸ‘‘πŸ’…πŸ¦‹

πŸ“¦ where this page comes from