| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
MCSP.Data.String.Text
Description
Textual conversion for strings.
Synopsis
- class ShowString a where
- showChars :: (Foldable f, Show a) => f a -> ShowS
- showCharsWith :: Foldable f => (a -> Char) -> f a -> ShowS
- showWords :: (Foldable f, Show a) => f a -> ShowS
- showWordsWith :: Foldable t => (a -> ShowS) -> t a -> ShowS
- class ReadString a where
- readChars :: Read a => ReadP [a]
- readCharsWith :: (Char -> Maybe a) -> ReadP [a]
- readWords :: Read a => ReadP [a]
- readWordsWith :: (String -> Maybe a) -> ReadP [a]
Specializable Show.
class ShowString a where Source #
Specializable String to text conversion.
Used for showing a string of the given character a.
Methods
Instances
| ShowString Char Source # |
|
| Show a => ShowString a Source # | |
showChars :: (Foldable f, Show a) => f a -> ShowS Source #
Shows all elements without quoting or separation.
This implementation uses the default converter for Show a.
>>>import Data.Int>>>import Data.List>>>data DNA = A | C | G | T deriving (Show, Read)
>>>showChars @[] @Int [1, 2, 12, 3, 56] """12\65533\&3\65533"
>>>showChars @[] @DNA [A, C, C, A] """ACCA"
showCharsWith :: Foldable f => (a -> Char) -> f a -> ShowS Source #
Shows all elements without quoting or separation.
>>>import Data.Int>>>import Data.List>>>import Numeric>>>data DNA = A | C | G | T deriving (Show, Read)
>>>showCharsWith (\n -> head $ showHex n "") [1, 2, 12] """12c"
>>>showCharsWith @[] @DNA (head . show) [A, C, C, A] """ACCA"
showWords :: (Foldable f, Show a) => f a -> ShowS Source #
Shows characters of a string separated by spaces.
This implementation uses the default converter for Show a.
>>>import Data.Int
>>>showWords @[] @Int [1, 2, 12] """1 2 12"
showWordsWith :: Foldable t => (a -> ShowS) -> t a -> ShowS Source #
Shows characters of a string separated by spaces.
>>>import Data.Int>>>import Numeric
>>>showWordsWith @[] @Int showHex [1, 2, 12] """1 2 c"
Specializable Read.
class ReadString a where Source #
Specializable text to String conversion.
Used for reading a string of the given character a.
Methods
readChars :: Read a => ReadP [a] Source #
Reads all elements without quoting or separation.
This implementation uses the default converter for Read a.
>>>import Data.Int>>>import MCSP.Text.ReadP>>>data DNA = A | C | G | T deriving (Show, Read)
>>>readP_to_S (readChars @Int) "1212"[([1,2,1,2],"")]
>>>readP_to_S (readChars @DNA) "TTGA"[([T,T,G,A],"")]
readCharsWith :: (Char -> Maybe a) -> ReadP [a] Source #
Reads all elements without quoting or separation.
>>>import Data.Int>>>import MCSP.Text.ReadP>>>import Text.Read.Lex>>>data DNA = A | C | G | T deriving (Show, Read)
>>>readP_to_S (readCharsWith @Int (\ch -> readMaybeP readHexP [ch])) "12c"[([1,2,12],"")]
>>>readP_to_S (readCharsWith @DNA (\ch -> readMaybeP readP [ch])) "TTGA"[([T,T,G,A],"")]
readWords :: Read a => ReadP [a] Source #
Reads characters of a string separated by spaces.
This implementation uses the default converter for Read a.
>>>import Data.Int>>>import MCSP.Text.ReadP
>>>readP_to_S (readWords @Int) "1 2 12"[([],"1 2 12"),([1],"2 12"),([1,2],"12"),([1,2,12],"")]
readWordsWith :: (String -> Maybe a) -> ReadP [a] Source #
Reads characters of a string separated by spaces.
>>>import Data.Int>>>import MCSP.Text.ReadP>>>import Text.Read.Lex
>>>readP_to_S (readWordsWith @Int $ readMaybeP readHexP) "1 2 c"[([],"1 2 c"),([1],"2 c"),([1,2],"c"),([1,2,12],"")]
>>>readP_to_S (readWordsWith $ readMaybeP word) " a xy b "[([],"a xy b "),(["a"],"xy b "),(["a","xy"],"b "),(["a","xy","b"],"")]