mcsp-algorithms-0.1.0: Algorithms for Minimum Common String Partition (MCSP) in Haskell.
Safe HaskellSafe-Inferred
LanguageGHC2021

MCSP.Data.String.Text

Description

Textual conversion for strings.

Synopsis

Specializable Show.

class ShowString a where Source #

Specializable String to text conversion.

Used for showing a string of the given character a.

Methods

showStr :: Foldable f => f a -> ShowS Source #

Shows characters of a String.

Show (String a) uses this specialized implementation.

Instances

Instances details
ShowString Char Source #

String Char represented by unseparated characters without quotes (abcd).

Instance details

Defined in MCSP.Data.String.Text

Methods

showStr :: Foldable f => f Char -> ShowS Source #

Show a => ShowString a Source # 
Instance details

Defined in MCSP.Data.String.Text

Methods

showStr :: Foldable f => f a -> ShowS 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

readStr :: ReadP [a] Source #

Read characters of a String.

Read (String a) uses this specialized implementation.

Instances

Instances details
ReadString Char Source #

String Char represented by unseparated characters without quotes (abcd).

Instance details

Defined in MCSP.Data.String.Text

Methods

readStr :: ReadP [Char] Source #

Read a => ReadString a Source # 
Instance details

Defined in MCSP.Data.String.Text

Methods

readStr :: ReadP [a] Source #

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"],"")]