Stdlib.Pqueue(3)

πŸ’… Stdlib.Pqueue(3) β€” the OCaml library one, bestie

okay so real talk: this page lives in the OCaml library manual, section 3. no gatekeeping, let's go 🫢


✨ NAME ✨

Stdlib.Pqueue β€” ngl the original literally just says "no description" 😭 which is giving minimal effort, but we move. it's the priority queue module, okay?

πŸ¦‹ Module πŸ¦‹

the whole thing is Module Stdlib.Pqueue, and underneath it's documented as:

Module Pqueue
 : (module Stdlib__Pqueue)

like yes queen, that's the internal name, we don't ask questions πŸ’…


πŸŽ€ the functors, one by one πŸŽ€

  • module type OrderedType = sig end β€” the input signature for the functors Pqueue.MakeMin and Pqueue.MakeMax. it's the vibe check your element type has to pass ✨
  • module type Min = sig end β€” the output signature of the functor Pqueue.MakeMin.
  • module MakeMin : (E : OrderedType) -> sig end β€” a functor that builds you an implementation of the min-priority queue structure, given a totally ordered type for elements. lowkey iconic.
  • module type Max = sig end β€” the output signature of the functor Pqueue.MakeMax.
  • module MakeMax : (E : OrderedType) -> sig end β€” same energy but flipped: a functor building a max-priority queue structure given a totally ordered type for elements. main character energy πŸ”₯

🌈 Polymorphic priority queues 🌈

okay this is the part where it gets more complex β€” the following functors create polymorphic queues of type 'a t, just like other polymorphic containers (lists, arrays…). they require a notion of "polymorphic elements" 'a elt that can be compared without depending on the values of 'a. yes bestie, comparison without peeking at the payload πŸ’œ

one usage scenario: when the user wants to pass priorities separately from the value stored in the queue. you do this by using pairs priority * 'a as elements. fr fr:

module Prio : OrderedType = ...

module PrioQueue = Pqueue.MakeMinPoly(struct
  type 'a t = Prio.t * 'a
  let compare (p1, _) (p2, _) = Prio.compare p1 p2
end)

(* for example, we now have: *)
PrioQueue.add: 'a PrioQueue.t -> Prio.t * 'a -> unit
PrioQueue.min_elt: 'a PrioQueue.t -> (Prio.t * 'a) option

to recap, since we're all about the details:

  • module type OrderedPolyType = sig end β€” the input signature of the functors Pqueue.MakeMinPoly and Pqueue.MakeMaxPoly. ✨
  • module type MinPoly = sig end β€” the output signature of the functor Pqueue.MakeMinPoly.
  • module MakeMinPoly : (E : OrderedPolyType) -> sig end β€” functor building an implementation of min-priority queues given a totally ordered type for the elements. slay πŸ’…
  • module type MaxPoly = sig end β€” the output signature of the functor Pqueue.MakeMaxPoly.
  • module MakeMaxPoly : (E : OrderedPolyType) -> sig end β€” functor building an implementation of max-priority queues given a totally ordered type for the elements. periodt. πŸ‘‘

πŸ’€ friendly reminder from your girl: every single one of these is a signature or functor with sig end / -> sig end in this doc β€” no extra functions are invented here, so don't come for me if you wanted more, that's literally all the page says 🫢

okay and finally the cute sign-off πŸ’–: this page was generated by OCamldoc, dated 2026-06-22, for Stdlib.Pqueue(3). stan a documentation tool that shows up on time. bye bestie, go build a queue πŸ¦‹βœ¨πŸŽ€

πŸ“¦ where this page comes from