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
    instance instToStringId {α : Type u_1} [ToString α] :
    Equations
      instance instToStringId_1 {α : Type u_1} [ToString α] :
      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
                instance instToStringULift {α : Type u} [ToString α] :
                Equations
                  instance instToStringFin (n : Nat) :
                  Equations
                    Equations
                      Instances For
                        instance instToStringOption {α : Type u} [ToString α] :
                        Equations
                          instance instToStringSum {α : Type u} {β : Type v} [ToString α] [ToString β] :
                          ToString (α β)
                          Equations
                            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 only consists of at least one decimal digit and optionally - in front. Leading + characters are not allowed.

                                  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 only consists of at least one decimal digit and optionally - in front. 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 only consists of at least one decimal digit and optionally - in front. Leading + characters are not allowed.

                                          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