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, use Parse.longident or Longident.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