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 raisesInvalid_argumentif 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
- 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