Module ISN.ISBN

International Standard Book Numbers (ISBNs)

type flavor =
  1. | SBN
    (*

    9-digit Standard Book Number

    *)
  2. | ISBN10
    (*

    10-digit ISBN

    *)
  3. | ISBN13
    (*

    13-digit ISBN

    *)

The type of ISBN flavors.

val string_of_flavor : flavor -> string

string_of_flavor converts a flavor value to a string.

type t = {
  1. flavor : flavor;
    (*

    variant type

    *)
  2. bn : string;
    (*

    book number

    *)
  3. cd : char;
    (*

    check digit

    *)
}

The type of parsed ISBNs.

val flavor : t -> flavor

(flavor t) is the flavor of the parsed ISBN t.

val bn : t -> string

(bn t) is the book number (exclusive of check digit) of the parsed ISBN t.

val cd : t -> char

(cd t) is the check digit of the parsed ISBN t.

val to_string : t -> string

to_string converts a parsed ISBN to a string representation.

val dump : t -> string

dump converts a parsed ISBN to a string suitable for debugging and testing.

val norm : string -> string
val parse : string -> t

(parse str) parses an ISBN.

The ISBN must have a check digit, but its validity is not checked; see valid.

See make to make a t from a book number (an ISBN without a check digit).

The ISBN will first be normalized.

  • raises Invalid_argument

    if the normalized bn is not of length 8, 9, or 12.

val check910 : string -> char

(check910 bn) computes the check digit from the book number part of a 9- or 10-digit ISBN.

The "book number" is the ISBN with the check digit removed. You can acquire a book number from an ISBN via (parse >> bn).

val check13 : string -> char

(check13 bn) computes the check digit from the book number part of a 13-digit ISBN.

The "book number" is the ISBN with the check digit removed. You can acquire a book number from an ISBN via (parse >> bn).

val compute : t -> char

(compute t) computes the check digit from a parsed ISBN.

Invariant: ∀t . (valid t) && (compute t = cd t).

val valid : t -> bool

(valid t) returns true if the parsed ISBN has a valid check digit and false otherwise.

val set : t -> t

(set t) computes and sets the check digit for the book number in t.

(set t) works whether or not (valid t).

Invariant: ∀t . (valid t) && (t = (set t))

val make : string -> t

(make bn) makes a parsed ISBN from book number bn.

A book number has no check digit. See parse to parse an ISBN with a check digit.

The book number will first be normalized.

  • raises Invalid_argument

    if the normalized bn is not of length 8, 9, or 12.

val to13 : t -> t

(to13 t) converts any flavor of ISBN to a 13-digit ISBN13.

This potentially changes the flavor and recomputes the check digit, as appropriate.

Invariants:

  • ∀t . (flavor t) = ISBN13 && (t = to13 t)
  • ∀t . (valid (to13 t))
  • ∀t . (flavor (to13 t) = ISBN13)