Stdlib.Char(3)

πŸ’– Stdlib.Char πŸ’–

okay so real talk bestie, this page is from the OCaml library manual, and it's your whole guide to the Char module β€” the little guy that handles single characters. πŸŽ€

🌸 NAME 🌸

Stdlib.Char β€” and ngl, the official description is literally "no description" 😭 that's it, that's the whole name section. We move.

πŸ¦‹ Module πŸ¦‹

Module Stdlib.Char β€” that's the module we're talking about, periodt.

✨ Documentation ✨

Alright so the real content lives here:

Module Char
 : (module Stdlib__Char)

That's the module alias situation β€” Char is literally an alias for the module Stdlib__Char. Slay. πŸ‘‘


πŸ“ Characters πŸ“

type t = char

t is an alias for the type of characters. That's the vibe β€” it's just char, no cap. πŸ’…


val code : char -> int

code c gives you the byte that corresponds to c. And here's the cute part: if c is an ASCII character, that byte corresponds to its encoding in ASCII or UTF-8. 🌈


val chr : int -> char

Returns the character with the integer code you hand it. Simple. ✨

⚠️ But bestie, it raises Invalid_argument if the argument is outside the range [ 0x00 ; 0xFF ]. Stay in your lane and you're fine. πŸ’€

val escaped : char -> string

Returns a string representing the given character, with special characters escaped following the lexical conventions of OCaml. All characters outside the ASCII printable range [ 0x20 ; 0x7E ] get escaped β€” and so do backslash, double-quote, and single-quote. Iconic escaping behaviour honestly. 🫢


🧚 Predicates and comparisons 🧚

ok first, a little pointer: see also the Char.Ascii module. πŸ‘€


val compare : t -> t -> int

The comparison function for characters, with the same specification as compare. Along with the type t, this function compare lets the module Char be passed as an argument to the functors Set.Make and Map.Make. πŸ”₯ And the order is compatible with Char.code β€” so everything stays consistent, as it should. πŸ’…


val equal : t -> t -> bool

The equal function for chars. That's it, that's the function. βœ…

Since 4.03


πŸŽ€ ASCII characters πŸŽ€

module Ascii : sig end

ASCII character set support, bestie! 🌟

These functions give meaning to the integers [ 0x00 ; 0x7F ] of the ASCII character set.

And here's the genuinely cool bit: since the UTF-8 encoding of Unicode has the same encoding and character semantics (U+0000 to U+001F) for these bytes, the functions can be safely used on elements of UTF-8 encoded string and bytes values. πŸ¦‹

BUT β€” and this is important β€” the functions only deal with ASCII related matters. For example, the notion of Unicode whitespace is much larger than the ASCII whitespace determined by Char.Ascii.is_white. So don't go thinking it's a full Unicode whitespace detector, because it is not. πŸ™ˆ

Since 5.4


val lowercase_ascii : char -> char

Use the equivalent Char.Ascii.lowercase instead. That's the whole note. πŸ‘‘

Since 4.03


val uppercase_ascii : char -> char

Use the equivalent Char.Ascii.uppercase instead. Same deal. ✨

Since 4.03


πŸ’œ Hashing πŸ’œ

val seeded_hash : int -> t -> int

A seeded hash function for characters, with the same output value as Hashtbl.seeded_hash. This function lets this module be passed as an argument to the functor Hashtbl.MakeSeeded. 🌸

Since 5.1


val hash : t -> int

An unseeded hash function for characters, with the same output value as Hashtbl.hash. This function lets this module be passed as an argument to the functor Hashtbl.Make. πŸ”₯

Since 5.1


and that's the whole page, bestie!! 🫢 go forth and character-handle responsibly πŸ’–

~ sign-off szn ~ this lil masterpiece was brought to you by OCamldoc, dated 2026-06-22, living at Stdlib.Char(3) β€” see you in the next manpage, mwah πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from