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

class Read a

Preliminary substitute for Read

Known Instances

Int

Member Functions

readRead a ⇒ String → a
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

splittedWordsString → [String]

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

Since this uses java.util.Regex.split the result will start with an empty string if the argument starts with spaces. This is a difference to words, which, according to the Haskell standard, does not include the empty string.

wordsString → [String]

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

unwords[String]String

unwords is an inverse operation to words.

It joins words with separating spaces.

Instances

instance Read Int

Member Functions

readStringInt
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, splittedWords, words

String → [Char]

Show_String.showChars

StringInt

Read_Int.read

[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

Read a ⇒ String → a

Read.read

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_(,).display, Show_(,).show

(Show 𝖇, Show 𝖆) ⇒ (𝖇, 𝖆) → [Char]

Show_(,).showChars

(Show 𝖇, Show 𝖆) ⇒ (𝖇 | 𝖆) → String

Show_Either.showsub, Show_Either.display, Show_Either.show

(Show 𝖇, Show 𝖆) ⇒ (𝖇 | 𝖆) → [Char]

Show_Either.showChars

(Show 𝖇, Show 𝖆) ⇒ [(𝖇, 𝖆)] → StringString

Show_(,).showList

(Show 𝖇, Show 𝖆) ⇒ [(𝖇 | 𝖆)] → StringString

Show_Either.showList

(Show 𝖇, Show 𝖆) ⇒ Int → (𝖇, 𝖆) → StringString

Show_(,).showsPrec

(Show 𝖇, Show 𝖆) ⇒ Int → (𝖇 | 𝖆) → StringString

Show_Either.showsPrec

(Show 𝖇, Show 𝖈, Show 𝖆) ⇒ (𝖇, 𝖈, 𝖆) → String

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

(Show 𝖇, Show 𝖈, Show 𝖆) ⇒ (𝖇, 𝖈, 𝖆) → [Char]

Show_(,,).showChars

(Show 𝖇, Show 𝖈, Show 𝖆) ⇒ [(𝖇, 𝖈, 𝖆)] → StringString

Show_(,,).showList

(Show 𝖇, Show 𝖈, Show 𝖆) ⇒ Int → (𝖇, 𝖈, 𝖆) → StringString

Show_(,,).showsPrec

Valid HTML 4.01 Strict