Documentation

Init.Data.ToString.Basic

class ToString (α : Type u) :

Types that can be converted into a string for display.

There is no expectation that the resulting string can be parsed back to the original data (see Repr for a similar class with this expectation).

  • toString : αString

    Converts a value into a string.

Instances
    Equations
    Equations
    Equations
    def List.toString {α : Type u_1} [ToString α] :
    List αString

    Converts a list into a string, using ToString.toString to convert its elements.

    The resulting string resembles list literal syntax, with the elements separated by ", " and enclosed in square brackets.

    The resulting string may not be valid Lean syntax, because there's no such expectation for ToString instances.

    Examples:

    Equations
    Instances For
      instance instToStringList {α : Type u} [ToString α] :
      Equations
      Equations
      instance instToStringULift {α : Type u} [ToString α] :
      Equations
      Equations
      Equations
      Equations
      Equations
      Equations
      instance instToStringFin (n : Nat) :
      Equations
      Equations
      Equations
      Equations
      Equations
      Equations
      Equations
      Equations
      Instances For
        instance instToStringOption {α : Type u} [ToString α] :
        Equations
        instance instToStringSum {α : Type u} {β : Type v} [ToString α] [ToString β] :
        ToString (α β)
        Equations
        • One or more equations did not get rendered due to their size.
        instance instToStringProd {α : Type u} {β : Type v} [ToString α] [ToString β] :
        ToString (α × β)
        Equations
        instance instToStringSigma {α : Type u} {β : αType v} [ToString α] [(x : α) → ToString (β x)] :
        Equations
        instance instToStringSubtype {α : Type u} {p : αProp} [ToString α] :
        Equations

        Interprets a string as the decimal representation of an integer, returning it. Returns none if the string does not contain a decimal integer.

        A string can be interpreted as a decimal integer if it is not empty, its first character is either '-' or a digit, and all remaining characters are digits.

        Use String.isInt to check whether String.toInt? would return some. String.toInt! is an alternative that panics instead of returning none when the string is not an integer.

        Examples:

        Equations
        Instances For

          Checks whether the string can be interpreted as the decimal representation of an integer.

          A string can be interpreted as a decimal integer if it is not empty, its first character is '-' or a digit, and all subsequent characters are digits. Leading + characters are not allowed.

          Use String.toInt? or String.toInt! to convert such a string to an integer.

          Examples:

          Equations
          Instances For

            Interprets a string as the decimal representation of an integer, returning it. Panics if the string does not contain a decimal integer.

            A string can be interpreted as a decimal integer if it is not empty, its first character is '-' or a digit, and all remaining characters are digits.

            Use String.isInt to check whether String.toInt! would return a value. String.toInt? is a safer alternative that returns none instead of panicking when the string is not an integer.

            Examples:

            Equations
            Instances For
              instance instToStringExcept {ε : Type u_1} {α : Type u_2} [ToString ε] [ToString α] :
              Equations
              instance instReprExcept {ε : Type u_1} {α : Type u_2} [Repr ε] [Repr α] :
              Repr (Except ε α)
              Equations
              • One or more equations did not get rendered due to their size.