Module Prelude.Char

This is Ocaml's standard Char with the additional functions from Chars.

include module type of struct include Stdlib.Char end
val code : char -> int
val chr : int -> char
val escaped : char -> string
val lowercase : char -> char
  • deprecated Use Char.lowercase_ascii instead.
val uppercase : char -> char
  • deprecated Use Char.uppercase_ascii instead.
val lowercase_ascii : char -> char
val uppercase_ascii : char -> char
type t = char
val compare : t -> t -> int
val equal : t -> t -> bool
val unsafe_chr : int -> char
include module type of struct include Chars end

Additional char functions.

N.B. These functions pertain only to chars as ASCII bytes.

val to_int : char -> int

to_int is Char.code.

val of_int : int -> char

of_int is Char.chr.

val upto : char -> char -> char list

(upto a b) is the list of the chars between a and b inclusive; not tail-recursive.

  • (upto '0' '9') = ['0';'1';'2';'3';'4';'5';'6';'7';'8';'9']
val (--) : char -> char -> char list

(--) is upto.

module Uppercase = Chars.Uppercase
module Lowercase = Chars.Lowercase
module Alphabetic = Chars.Alphabetic
module Decimal = Chars.Decimal
module Octal = Chars.Octal
module Hex = Chars.Hex

Development Utils

val to_string : char -> string

(to_string c) is the string containing just the character c.

Invariants:

  • String.len (to_string c) = 1
  • String.get (to_string c) 0 = c
val print : char -> unit

print is (to_string >> print_endline).

val random : ?printable:bool -> ?charset:char list -> unit -> char

(random ?(printable=true) ?charset ()) is a random printable ASCII character in the range [0x20 -- 0x7E].

If (printable = false), the result is a random ASCII character in the range [0x00 -- 0x7E].

If charset is provided, it trumps printable and the characters will be chosen from this list.

Partially apply for efficiency.

  • raises Invalid_argument

    if (Some charset) is empty.

Ops

module Ops = Chars.Ops