Longident(3)
π NAME π
hey bestie, welcome to the Longident(3) page in the OCaml library manual β we're talking about long identifiers, the kind used in parsetree. π
π§ MODULE π§
Module Longident
: sig end
Long identifiers, used in parsetree. That's the whole vibe.
β οΈ Warning: this module is unstable and part of Compiler_libs. Bestie, it said what it said β handle with care. π
If you wanna print a longident, go see Pprintast.longident, using Format.asprintf to convert it to a string. β¨
β¨ DOCUMENTATION β¨
Module Longident
: sig end
Okay so first up, the type β and yes, every constructor is staying exactly like this:
type t =
| Lident of string
| Ldot of t Location.loc * string Location.loc
| Lapply of t Location.loc * t Location.loc
val same : t -> t -> bool
same t t' compares the longidents t and t' without taking locations into account. Lowkey iconic: locations are not invited to this comparison. π
val flatten : t -> string list
val unflatten : string list -> t option
For a non-empty list l, unflatten l is Some lid where lid is the long identifier created by concatenating the elements of l with Ldot. unflatten [] is None. Fr fr, empty list? None. π«Ά
val last : t -> string
val parse : string -> t
β οΈ Deprecated. this function may misparse its input, useParse.longidentorLongident.unflatten.
This function is broken on identifiers that are not just "Word.Word.word"; for example, it returns incorrect results on infix operators and extended module paths. Not me defending it β it's literally broken. π
If you want to generate long identifiers that are a list of dot-separated identifiers, the function Longident.unflatten is safer and faster. Longident.unflatten is available since OCaml 4.06.0. π
If you want to parse any identifier correctly, use the long-identifiers functions from the Parse module, in particular Parse.longident. They are available since OCaml 4.11, and also provide proper input-location support. Slay. π
okay bye bestie β this page was brought to you by OCamldoc, dated 2026-06-22, and it's literally the Longident(3) manual page. πβ¨π¦
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms