Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data ASCII (superset :: Type)
- lift :: ASCII superset -> superset
- asciiUnsafe :: superset -> ASCII superset
- validateChar :: CharSuperset superset => superset -> Maybe (ASCII superset)
- fromChar :: CharSuperset superset => Char -> ASCII superset
- toChar :: CharSuperset superset => ASCII superset -> Char
- substituteChar :: CharSuperset superset => superset -> ASCII superset
- asChar :: CharSuperset superset => (Char -> Char) -> ASCII superset -> ASCII superset
- validateString :: StringSuperset superset => superset -> Maybe (ASCII superset)
- fromCharList :: StringSuperset superset => [Char] -> ASCII superset
- toCharList :: StringSuperset superset => ASCII superset -> [Char]
- substituteString :: StringSuperset superset => superset -> ASCII superset
- mapChars :: StringSuperset superset => (Char -> Char) -> ASCII superset -> ASCII superset
ASCII type constructor
data ASCII (superset :: Type) Source #
This type constructor indicates that a value from some ASCII superset is valid ASCII
The type parameter is the ASCII superset, which should be a type with an
instance of either CharSuperset
or StringSuperset
.
For example, whereas a Text
value may contain a combination of ASCII
and non-ASCII characters, a value of type
may contain
only ASCII characters.ASCII
Text
Instances
asciiUnsafe :: superset -> ASCII superset Source #
Change the type of an ASCII superset value that is known to be valid ASCII
This is "unsafe" because this assertion is unchecked, so this function is capable
of producing an invalid ASCII
value.
Character functions
validateChar :: CharSuperset superset => superset -> Maybe (ASCII superset) Source #
(map validateChar [-1, 65, 97, 128] :: [Maybe (ASCII Int)]) == [Nothing, Just (asciiUnsafe 65), Just (asciiUnsafe 97), Nothing]
substituteChar :: CharSuperset superset => superset -> ASCII superset Source #
String functions
validateString :: StringSuperset superset => superset -> Maybe (ASCII superset) Source #
(map validateString ["Hello", "Cristóbal"] :: [Maybe (ASCII Text)]) == [Just (asciiUnsafe "Hello"), Nothing] (map validateString ["Hello", "Cristóbal"] :: [Maybe (ASCII String)]) == [Just (asciiUnsafe "Hello"), Nothing]
fromCharList :: StringSuperset superset => [Char] -> ASCII superset Source #
fromCharList [CapitalLetterH, SmallLetterI, ExclamationMark] == (asciiUnsafe "Hi!" :: ASCII Text)
toCharList :: StringSuperset superset => ASCII superset -> [Char] Source #
toCharList (substituteString "Piñata" :: ASCII Text) == [CapitalLetterP, SmallLetterI, Substitute, SmallLetterA, SmallLetterT, SmallLetterA]
substituteString :: StringSuperset superset => superset -> ASCII superset Source #
Forces a string from a larger character set into ASCII by using the
Substitute
character in place of any non-ASCII characters
(substituteString "Cristóbal" :: ASCII Text) == asciiUnsafe "CristSUBbal"