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.

⚠️ Raises Invalid_argument if 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