Char(3)
π NAME π
Char β character operations, bestie. that's the whole vibe.
π MODULE π
okay so the module is literally called Char, and its signature is:
Module Char
: sig end
slay. now let's get into it π
β¨ DOCUMENTATION β¨
π¦ Module Char
: sig end
Character operations, periodt. here's the tea:
Characters are the elements of string and bytes values. Characters represent bytes β that means an integer in the range [ 0x00 ; 0xFF ]. yes, all of them, no cap.
Some of the functions in this module interpret the characters in the range [ 0x00 ; 0x7F ] as the characters of the ASCII character set. iykyk πΈ
π Characters
type t = char
an alias for the type of characters. iconic, no notes.
val code : char -> int
code c is the byte corresponding to c. If c is an ASCII character, this corresponds to its encoding in ASCII or UTF-8. lowkey elegant β¨
val chr : int -> char
Returns the character with the given integer code.
β οΈ RaisesInvalid_argumentif the argument is outside the range[ 0x00 ; 0xFF ]. so like. don't do that, bestie π
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, plus backslash, double-quote, and single-quote. it's giving safety first π«Ά
πΈ Predicates and comparisons
π«Ά 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 allows the module Char to be passed as an argument to the functors Set.Make and Map.Make. the order is compatible with Char.code. functor-ready, we love to see it π
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, babes π
These functions give meaning to the integers [ 0x00 ; 0x7F ] of the ASCII character set.
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 the important part β 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. do not come for ASCII with your Unicode expectations π
Since 5.4
val lowercase_ascii : char -> char
Use the equivalent Char.Ascii.lowercase instead. (yes this is the redirect era)
Since 4.03
val uppercase_ascii : char -> char
Use the equivalent Char.Ascii.uppercase instead. (same energy, same redirect)
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 allows this module to be passed as an argument to the functor Hashtbl.MakeSeeded. seeded hashing ate, fr fr π₯
Since 5.1
val hash : t -> int
an unseeded hash function for characters, with the same output value as Hashtbl.hash. this function allows this module to be passed as an argument to the functor Hashtbl.Make. the plain one. still iconic π
Since 5.1
okay that's the whole page bestie, go pass Char to a functor and live your best life π¦π
this page was served fresh by OCamldoc, dated 2026-06-22 β Char(3) and out πβ¨
π¦ 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