Module Prelude.PreludeText

Classes and Instances to convert values to Strings (Show.show) and Strings to values ("read").

There are a few differences to Haskell, notably

Imports

Table of Content

Definitions

type ShowS = StringJ CharStringJ Char

Haskell compatibility

type ReadS a = StringJ Char → [(a, StringJ Char)]

Haskell compatibility

class Show show

Class Show provides operations to convert values to Strings.

This class can be derived for all algebraic data types whose constituents are themselves instances of Show.

Known Instances

Bool, (), (,), (,,), Int, Char, Lang.Byte, Either, Double, Float, StringJ, Ordering, Long, Integer, Maybe, Lang.Short, Regex, [], Throwable

Member Functions

displayShow show ⇒ show → String

Show.display computes an alternate string representation of a value and is used in the Char and String instances of Show to produce an unquoted string.

The default implementation is to do the same as Show.show.

showShow show ⇒ show → String

Computes the string representation of a value.

Every instance must implement Show.show.

showCharsShow show ⇒ show → [Char]

Show.showChars addresses the problem of Show.showing infinite values. Because Show.show has type String and String is atomic, this would try to create a string with infinite length, and hence is doomed to fail.

The default definition is

 showChars = String.toList . show

This is ok for all finite values. But instances for recursive types should implement it in a way that produces a lazy list of characters.

Here is an example for the list instance:

 showChars [] = ['[', ']']
 showChars xs = '[' : ( tail [ c | x <- xs, c <- ',' : showChars x ] ++ [']'] )
showListShow show ⇒ [show] → StringString

Haskell compatibility

showsPrecShow show ⇒ Int → show → StringString

Haskell compatibility

showsubShow show ⇒ show → String

Show.showsub is used for Show.showing elements of a value of an algebraic data type in derived instances of Show.

The generated code in derived instances for types that are not enumerations is

 showsub x = "(" ++ show x ++ ")"

so that values are enclosed in parentheses. Certain types like records, lists, tuples and many primitive types do not need extra parentheses, and thus Show.showsub is the same as Show.show, which is also the default implementation.

In short,

Example:

 derive Show ( Maybe b)

implements the following:

 show Nothing = "Nothing"
 show (Just x) = "Just " ++ x.showsub
 showsub x = "(" ++ show x ++ ")"

so that

 show (Just (Just 42)) == "Just (Just 42)"
joinedString[String]String

joined sep xs concatenates all strings in /xs/, and inserts /sep/ between any two elements of /xs/.

If /xs/ is empty, the result is an empty string. If /sep/ is an empty string, then the result is just the concatenation of the strings in /xs/.

Example:

 joined ", " ["aaa", "bbb", "ccc"] == "aaa, bbb, ccc"
packed[Char]String

convert a list of characters to a string

 packed ['a', 'b', 'c' ] == "abc"
showsShow a ⇒ a → StringString

Haskell compatibility

showCharCharStringString

Haskell compatibility

showStringStringStringString

Haskell compatibility

showParenBool → (StringString) → StringString

Haskell compatibility

linesString → [String]

splits a String on end-of-line and returns a list of Strings

The last line may or may not be terminated by newline.

End-of-line is signaled by a number of carriage returns followed by a new line.

This should work for UNIX and Windows.

lineSeparatorString

The line separator suitable for the platform the program is running on.

unlines[String]String

unlines is an inverse operation to lines.

It joins lines, after appending a terminating newline to each.

chompStringString

strip trailing spaces, tabs, newline and carriage return characters from a string

wordsString → [String]

splits a String on non empty sequences of spaces and returns a list of Strings

unwords[String]String

unwords is an inverse operation to words.

It joins words with separating spaces.

Instances

instance Show ()

Member Functions

display()String

inherited from Show.display

show()String

Function generated for derived instance.

showChars() → [Char]

inherited from Show.showChars

showList[()]StringString

inherited from Show.showList

showsPrecInt()StringString

inherited from Show.showsPrec

showsub()String

Function generated for derived instance.

instance (Show a, Show b) ⇒ Show (a, b)

Member Functions

display ∷ (Show β, Show α) ⇒ (β, α)String

inherited from Show.display

show ∷ (Show α, Show β) ⇒ (α, β)String

Function generated for derived instance.

showChars ∷ (Show α, Show β) ⇒ (α, β) → [Char]

inherited from Show.showChars

showList ∷ (Show α, Show β) ⇒ [(α, β)]StringString

inherited from Show.showList

showsPrec ∷ (Show α, Show β) ⇒ Int(α, β)StringString

inherited from Show.showsPrec

showsub ∷ (Show α, Show β) ⇒ (α, β)String

inherited from Show.showsub

instance (Show a, Show b, Show c) ⇒ Show (a, b, c)

Member Functions

display ∷ (Show γ, Show β, Show α) ⇒ (γ, β, α)String

inherited from Show.display

show ∷ (Show β, Show α, Show γ) ⇒ (β, α, γ)String

Function generated for derived instance.

showChars ∷ (Show β, Show α, Show γ) ⇒ (β, α, γ) → [Char]

inherited from Show.showChars

showList ∷ (Show α, Show γ, Show β) ⇒ [(α, γ, β)]StringString

inherited from Show.showList

showsPrec ∷ (Show γ, Show β, Show α) ⇒ Int(γ, β, α)StringString

inherited from Show.showsPrec

showsub ∷ (Show α, Show γ, Show β) ⇒ (α, γ, β)String

inherited from Show.showsub

instance Show Bool

Member Functions

displayBoolString

inherited from Show.display

showBoolString
showCharsBool → [Char]

inherited from Show.showChars

showList[Bool]StringString

inherited from Show.showList

showsPrecIntBoolStringString

inherited from Show.showsPrec

showsubBoolString

inherited from Show.showsub

instance Show Byte

Member Functions

displayByteString

inherited from Show.display

showByteString
showCharsByte → [Char]

inherited from Show.showChars

showList[Byte]StringString

inherited from Show.showList

showsPrecIntByteStringString

inherited from Show.showsPrec

showsubByteString

inherited from Show.showsub

instance Show Char

Member Functions

displayCharString

construct a string that consists of just this character

showCharString
pure native frege.runtime.Runtime.quoteChr

reconstructs a Java char literal from a character, i.e.

 show 'a' = "'a'"   
showCharsChar → [Char]

inherited from Show.showChars

showList[Char]StringString

the string created from the characters

showsPrecIntCharStringString

inherited from Show.showsPrec

showsubCharString

inherited from Show.showsub

instance Show Double

Member Functions

displayDoubleString

inherited from Show.display

showDoubleString
pure native java.lang.Double.toString
showCharsDouble → [Char]

inherited from Show.showChars

showList[Double]StringString

inherited from Show.showList

showsPrecIntDoubleStringString

inherited from Show.showsPrec

showsubDoubleString

inherited from Show.showsub

instance (Show a, Show b) ⇒ Show (a | b)

Member Functions

display ∷ (Show α, Show β) ⇒ (α | β)String

inherited from Show.display

show ∷ (Show α, Show β) ⇒ (α | β)String

Function generated for derived instance.

showChars ∷ (Show α, Show β) ⇒ (α | β) → [Char]

inherited from Show.showChars

showList ∷ (Show β, Show α) ⇒ [(β | α)]StringString

inherited from Show.showList

showsPrec ∷ (Show α, Show β) ⇒ Int(α | β)StringString

inherited from Show.showsPrec

showsub ∷ (Show β, Show α) ⇒ (β | α)String

Function generated for derived instance.

instance Show Float

Member Functions

displayFloatString

inherited from Show.display

showFloatString
pure native java.lang.Float.toString
showCharsFloat → [Char]

inherited from Show.showChars

showList[Float]StringString

inherited from Show.showList

showsPrecIntFloatStringString

inherited from Show.showsPrec

showsubFloatString

inherited from Show.showsub

instance Show Int

Member Functions

displayIntString

inherited from Show.display

showIntString
pure native java.lang.String.valueOf

the String representation of the Int argument, uses java.lang.String.valueOf

showCharsInt → [Char]

inherited from Show.showChars

showList[Int]StringString

inherited from Show.showList

showsPrecIntIntStringString

inherited from Show.showsPrec

showsubIntString

inherited from Show.showsub

instance Show Integer

Member Functions

displayIntegerString

inherited from Show.display

showIntegerString
pure native toString

the String representation of the Integer argument, uses BigInteger.toString

showCharsInteger → [Char]

inherited from Show.showChars

showList[Integer]StringString

inherited from Show.showList

showsPrecIntIntegerStringString

inherited from Show.showsPrec

showsubIntegerString

inherited from Show.showsub

instance Show Long

Member Functions

displayLongString

inherited from Show.display

showLongString
pure native java.lang.Long.toString

the String representation of the Long argument, uses java.lang.Long.toString

showCharsLong → [Char]

inherited from Show.showChars

showList[Long]StringString

inherited from Show.showList

showsPrecIntLongStringString

inherited from Show.showsPrec

showsubLongString

inherited from Show.showsub

instance Show a ⇒ Show (Maybe a)

Member Functions

displayShow α ⇒ Maybe αString

inherited from Show.display

showShow α ⇒ Maybe αString

Function generated for derived instance.

showCharsShow α ⇒ Maybe α → [Char]

inherited from Show.showChars

showListShow α ⇒ [Maybe α]StringString

inherited from Show.showList

showsPrecShow α ⇒ IntMaybe αStringString

inherited from Show.showsPrec

showsubShow α ⇒ Maybe αString

Function generated for derived instance.

instance Show Ordering

Member Functions

displayOrderingString

inherited from Show.display

showOrderingString

Function generated for derived instance.

showCharsOrdering → [Char]

inherited from Show.showChars

showList[Ordering]StringString

inherited from Show.showList

showsPrecIntOrderingStringString

inherited from Show.showsPrec

showsubOrderingString

Function generated for derived instance.

instance Show Regex

Member Functions

displayRegexString

inherited from Show.display

showRegexString
showCharsRegex → [Char]

inherited from Show.showChars

showList[Regex]StringString

inherited from Show.showList

showsPrecIntRegexStringString

inherited from Show.showsPrec

showsubRegexString

inherited from Show.showsub

instance Show Short

Member Functions

displayShortString

inherited from Show.display

showShortString
showCharsShort → [Char]

inherited from Show.showChars

showList[Short]StringString

inherited from Show.showList

showsPrecIntShortStringString

inherited from Show.showsPrec

showsubShortString

inherited from Show.showsub

instance Show String

Member Functions

displayStringString
showStringString
pure native frege.runtime.Runtime.quoteStr

reconstructs a Java string literal from a string, i.e.

 show "abc" = "\"abc\""   
showCharsString → [Char]

inherited from Show.showChars

showList[String]StringString

inherited from Show.showList

showsPrecIntStringStringString

inherited from Show.showsPrec

showsubStringString

inherited from Show.showsub

instance Show Throwable

Member Functions

displayThrowableString

inherited from Show.display

showThrowableString

creates a string representation of a Java exception, consisting of the class name and the message, like

 "java.lang.ArithmeticException: division by zero"
showCharsThrowable → [Char]

inherited from Show.showChars

showList[Throwable]StringString

inherited from Show.showList

showsPrecIntThrowableStringString

inherited from Show.showsPrec

showsubThrowableString

inherited from Show.showsub

instance Show a ⇒ Show [a]

Member Functions

displayShow α ⇒ [α] → String

inherited from Show.display

showShow α ⇒ [α] → String
showCharsShow α ⇒ [α] → [Char]
showListShow α ⇒ [[α]]StringString

inherited from Show.showList

showsPrecShow α ⇒ Int → [α] → StringString

inherited from Show.showsPrec

showsubShow α ⇒ [α] → String

inherited from Show.showsub

Functions and Values by Type

StringStringString

showString

String → [String] → String

joined

StringString

chomp, Show_String.showsub, Show_String.display, Show_String.show

String → [String]

lines, words

String → [Char]

Show_String.showChars

[String] → StringString

Show_String.showList

[String] → String

unlines, unwords

[Byte] → StringString

Show_Byte.showList

[Short] → StringString

Show_Short.showList

[Regex] → StringString

Show_Regex.showList

[()] → StringString

Show_().showList

[Bool] → StringString

Show_Bool.showList

[Char] → StringString

Show_Char.showList

[Char] → String

packed

[Double] → StringString

Show_Double.showList

[Float] → StringString

Show_Float.showList

[Int] → StringString

Show_Int.showList

[Integer] → StringString

Show_Integer.showList

[Long] → StringString

Show_Long.showList

[Ordering] → StringString

Show_Ordering.showList

[Throwable] → StringString

Show_Throwable.showList

ByteString

Show_Byte.showsub, Show_Byte.display, Show_Byte.show

Byte → [Char]

Show_Byte.showChars

ShortString

Show_Short.showsub, Show_Short.display, Show_Short.show

Short → [Char]

Show_Short.showChars

RegexString

Show_Regex.showsub, Show_Regex.display, Show_Regex.show

Regex → [Char]

Show_Regex.showChars

()String

Show_().showsub, Show_().display, Show_().show

() → [Char]

Show_().showChars

Bool → (StringString) → StringString

showParen

BoolString

Show_Bool.showsub, Show_Bool.display, Show_Bool.show

Bool → [Char]

Show_Bool.showChars

CharStringString

showChar

CharString

Show_Char.showsub, Show_Char.display, Show_Char.show

Char → [Char]

Show_Char.showChars

DoubleString

Show_Double.showsub, Show_Double.display, Show_Double.show

Double → [Char]

Show_Double.showChars

FloatString

Show_Float.showsub, Show_Float.display, Show_Float.show

Float → [Char]

Show_Float.showChars

IntStringStringString

Show_String.showsPrec

IntByteStringString

Show_Byte.showsPrec

IntShortStringString

Show_Short.showsPrec

IntRegexStringString

Show_Regex.showsPrec

Int()StringString

Show_().showsPrec

IntBoolStringString

Show_Bool.showsPrec

IntCharStringString

Show_Char.showsPrec

IntDoubleStringString

Show_Double.showsPrec

IntFloatStringString

Show_Float.showsPrec

IntIntStringString

Show_Int.showsPrec

IntIntegerStringString

Show_Integer.showsPrec

IntLongStringString

Show_Long.showsPrec

IntOrderingStringString

Show_Ordering.showsPrec

IntThrowableStringString

Show_Throwable.showsPrec

IntString

Show_Int.showsub, Show_Int.display, Show_Int.show

Int → [Char]

Show_Int.showChars

IntegerString

Show_Integer.showsub, Show_Integer.display, Show_Integer.show

Integer → [Char]

Show_Integer.showChars

LongString

Show_Long.showsub, Show_Long.display, Show_Long.show

Long → [Char]

Show_Long.showChars

OrderingString

Show_Ordering.showsub, Show_Ordering.display, Show_Ordering.show

Ordering → [Char]

Show_Ordering.showChars

ThrowableString

Show_Throwable.showsub, Show_Throwable.display, Show_Throwable.show

Throwable → [Char]

Show_Throwable.showChars

String

lineSeparator

Show a ⇒ a → StringString

shows

Show show ⇒ [show] → StringString

Show.showList

Show show ⇒ Int → show → StringString

Show.showsPrec

Show show ⇒ show → String

Show.showsub, Show.display, Show.show

Show show ⇒ show → [Char]

Show.showChars

Show α ⇒ Maybe α → String

Show_Maybe.showsub, Show_Maybe.display, Show_Maybe.show

Show α ⇒ Maybe α → [Char]

Show_Maybe.showChars

Show α ⇒ [Maybe α] → StringString

Show_Maybe.showList

Show α ⇒ [[α]] → StringString

Show_[].showList

Show α ⇒ [α] → String

Show_[].showsub, Show_[].display, Show_[].show

Show α ⇒ [α] → [Char]

Show_[].showChars

Show α ⇒ IntMaybe α → StringString

Show_Maybe.showsPrec

Show α ⇒ Int → [α] → StringString

Show_[].showsPrec

(Show α, Show β) ⇒ (α, β) → String

Show_(,).showsub, Show_(,).show

(Show α, Show β) ⇒ (α, β) → [Char]

Show_(,).showChars

(Show α, Show β) ⇒ (α | β) → String

Show_Either.display, Show_Either.show

(Show α, Show β) ⇒ (α | β) → [Char]

Show_Either.showChars

(Show α, Show β) ⇒ [(α, β)] → StringString

Show_(,).showList

(Show α, Show β) ⇒ Int → (α, β) → StringString

Show_(,).showsPrec

(Show α, Show β) ⇒ Int → (α | β) → StringString

Show_Either.showsPrec

(Show β, Show α) ⇒ (β, α) → String

Show_(,).display

(Show β, Show α) ⇒ (β | α) → String

Show_Either.showsub

(Show β, Show α) ⇒ [(β | α)] → StringString

Show_Either.showList

(Show α, Show γ, Show β) ⇒ (α, γ, β) → String

Show_(,,).showsub

(Show α, Show γ, Show β) ⇒ [(α, γ, β)] → StringString

Show_(,,).showList

(Show β, Show α, Show γ) ⇒ (β, α, γ) → String

Show_(,,).show

(Show β, Show α, Show γ) ⇒ (β, α, γ) → [Char]

Show_(,,).showChars

(Show γ, Show β, Show α) ⇒ (γ, β, α) → String

Show_(,,).display

(Show γ, Show β, Show α) ⇒ Int → (γ, β, α) → StringString

Show_(,,).showsPrec

Valid HTML 4.01 Strict