Copyright | (c) gspia 2020- |
---|---|
License | BSD |
Maintainer | gspia |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Fcf.Data.Text
We mimick Data.Text but on type level. The internal representation is based on type level lists.
Synopsis
- data Text = Text Symbol
- data Empty :: Exp Text
- data Singleton :: Symbol -> Exp Text
- data FromList :: [Text] -> Exp Text
- data FromSymbolList :: [Symbol] -> Exp Text
- data ToList :: Text -> Exp [Text]
- data ToSymbol :: Text -> Exp Symbol
- data ToSymbolList :: Text -> Exp [Symbol]
- data Null :: Text -> Exp Bool
- data Length :: Text -> Exp Nat
- data Append :: Text -> Text -> Exp Text
- data Cons :: Symbol -> Text -> Exp Text
- data Snoc :: Text -> Symbol -> Exp Text
- data Uncons :: Text -> Exp (Maybe (Symbol, Text))
- data Unsnoc :: Text -> Exp (Maybe (Symbol, Text))
- data Head :: Text -> Exp (Maybe Symbol)
- data Tail :: Text -> Exp (Maybe Text)
- data Init :: Text -> Exp (Maybe Text)
- data CompareLength :: Text -> Nat -> Exp Ordering
- data FMap :: (Symbol -> Exp Symbol) -> Text -> Exp Text
- data Intercalate :: Text -> [Text] -> Exp Text
- data Intersperse :: Symbol -> Text -> Exp Text
- data Reverse :: Text -> Exp Text
- data Replace :: Text -> Text -> Text -> Exp Text
- data Concat :: [Text] -> Exp Text
- data FConcatMap :: (Symbol -> Exp Text) -> Text -> Exp Text
- data Any :: (Symbol -> Exp Bool) -> Text -> Exp Bool
- data All :: (Symbol -> Exp Bool) -> Text -> Exp Bool
- data Take :: Nat -> Text -> Exp Text
- data TakeEnd :: Nat -> Text -> Exp Text
- data Drop :: Nat -> Text -> Exp Text
- data DropEnd :: Nat -> Text -> Exp Text
- data TakeWhile :: (Symbol -> Exp Bool) -> Text -> Exp Text
- data TakeWhileEnd :: (Symbol -> Exp Bool) -> Text -> Exp Text
- data DropWhile :: (Symbol -> Exp Bool) -> Text -> Exp Text
- data DropWhileEnd :: (Symbol -> Exp Bool) -> Text -> Exp Text
- data DropAround :: (Symbol -> Exp Bool) -> Text -> Exp Text
- data Strip :: Text -> Exp Text
- data SplitOn :: Text -> Text -> Exp [Text]
- data Split :: (Symbol -> Exp Bool) -> Text -> Exp [Text]
- data Lines :: Text -> Exp [Text]
- data Words :: Text -> Exp [Text]
- data Unlines :: [Text] -> Exp Text
- data Unwords :: [Text] -> Exp Text
- data IsPrefixOf :: Text -> Text -> Exp Bool
- data IsSuffixOf :: Text -> Text -> Exp Bool
- data IsInfixOf :: Text -> Text -> Exp Bool
Documentation
Text
is a data structure, that is, a list to hold type-level symbols of
length one.
Instances
Creation
data Empty :: Exp Text Source #
Empty
Example
>>>
:kind! (Eval Empty :: Text)
(Eval Empty :: Text) :: Text = 'Text ""
See also the other examples in this module.
data Singleton :: Symbol -> Exp Text Source #
Singleton
Example
>>>
:kind! Eval (Singleton "a")
Eval (Singleton "a") :: Text = 'Text "a"
data FromSymbolList :: [Symbol] -> Exp Text Source #
Use FromList to construct a Text from type-level list.
Example
:kind! Eval (FromSymbolList '["h", "e", "l", "l", "u", "r", "e", "i"]) Eval (FromSymbolList '["h", "e", "l", "l", "u", "r", "e", "i"]) :: Text = 'Text "hellurei"
Instances
type Eval (FromSymbolList sym :: Text -> Type) Source # | |
Defined in Fcf.Data.Text |
data ToSymbol :: Text -> Exp Symbol Source #
ToSymbol
Example
>>>
:kind! Eval (ToSymbol =<< FromSymbolList '["w", "o", "r", "d"])
Eval (ToSymbol =<< FromSymbolList '["w", "o", "r", "d"]) :: Symbol = "word"
data ToSymbolList :: Text -> Exp [Symbol] Source #
Get the type-level list out of the Text
.
Example
>>>
:kind! Eval (ToSymbolList =<< FromSymbolList '["a", "b"])
Eval (ToSymbolList =<< FromSymbolList '["a", "b"]) :: [Symbol] = '["a", "b"]
Instances
type Eval (ToSymbolList ('Text sym) :: [Symbol] -> Type) Source # | |
Defined in Fcf.Data.Text |
Basic Interface
data Null :: Text -> Exp Bool Source #
Null
Example
>>>
:kind! Eval (Null ('Text "ab"))
Eval (Null ('Text "ab")) :: Bool = 'False
>>>
:kind! Eval (Null =<< Empty)
Eval (Null =<< Empty) :: Bool = 'True
data Length :: Text -> Exp Nat Source #
Length
Example
>>>
:kind! Eval (Length =<< Singleton "ab")
Eval (Length =<< Singleton "ab") :: Nat = 2
data Append :: Text -> Text -> Exp Text Source #
Append two type-level texts.
Example
>>>
:kind! Eval (Append ('Text "aa") ('Text "mu"))
Eval (Append ('Text "aa") ('Text "mu")) :: Text = 'Text "aamu"
data Cons :: Symbol -> Text -> Exp Text Source #
Add a symbol to the beginning of a type-level text.
Example
>>>
:kind! Eval (Cons "h" ('Text "aamu"))
Eval (Cons "h" ('Text "aamu")) :: Text = 'Text "haamu"
data Snoc :: Text -> Symbol -> Exp Text Source #
Add a symbol to the end of a type-level text.
Example
>>>
:kind! Eval (Snoc ('Text "aam") "u")
Eval (Snoc ('Text "aam") "u") :: Text = 'Text "aamu"
data Uncons :: Text -> Exp (Maybe (Symbol, Text)) Source #
Get the first symbol from type-level text.
Example
>>>
:kind! Eval (Uncons ('Text "haamu"))
Eval (Uncons ('Text "haamu")) :: Maybe (Symbol, Text) = 'Just '("h", 'Text "aamu")
>>>
:kind! Eval (Uncons ('Text ""))
Eval (Uncons ('Text "")) :: Maybe (Symbol, Text) = 'Nothing
data Unsnoc :: Text -> Exp (Maybe (Symbol, Text)) Source #
Get the last symbol from type-level text.
Example
>>>
:kind! Eval (Unsnoc ('Text "aamun"))
Eval (Unsnoc ('Text "aamun")) :: Maybe (Symbol, Text) = 'Just '("n", 'Text "aamu")
>>>
:kind! Eval (Unsnoc ('Text ""))
Eval (Unsnoc ('Text "")) :: Maybe (Symbol, Text) = 'Nothing
data Head :: Text -> Exp (Maybe Symbol) Source #
Get the first symbol of type-level text.
Example
>>>
:kind! Eval (Head ('Text "aamu"))
Eval (Head ('Text "aamu")) :: Maybe Symbol = 'Just "a"
>>>
:kind! Eval (Head ('Text ""))
Eval (Head ('Text "")) :: Maybe Symbol = 'Nothing
data Tail :: Text -> Exp (Maybe Text) Source #
Get the tail of a type-level text.
Example
>>>
:kind! Eval (Tail ('Text "haamu"))
Eval (Tail ('Text "haamu")) :: Maybe Text = 'Just ('Text "aamu")
>>>
:kind! Eval (Tail ('Text ""))
Eval (Tail ('Text "")) :: Maybe Text = 'Nothing
data Init :: Text -> Exp (Maybe Text) Source #
Take all except the last symbol from type-level text.
Example
>>>
:kind! Eval (Init ('Text "aamun"))
Eval (Init ('Text "aamun")) :: Maybe Text = 'Just ('Text "aamu")
>>>
:kind! Eval (Init ('Text ""))
Eval (Init ('Text "")) :: Maybe Text = 'Nothing
data CompareLength :: Text -> Nat -> Exp Ordering Source #
Compare the length of type-level text to given Nat and give the Ordering.
Example
>>>
:kind! Eval (CompareLength ('Text "aamu") 3)
Eval (CompareLength ('Text "aamu") 3) :: Ordering = 'GT
Instances
type Eval (CompareLength txt n :: Ordering -> Type) Source # | |
Defined in Fcf.Data.Text |
Transformation
data FMap :: (Symbol -> Exp Symbol) -> Text -> Exp Text Source #
FMap for type-level text.
Example
>>>
:{
data IsIsymb :: Symbol -> Exp Bool type instance Eval (IsIsymb s) = Eval ("i" S.== s) data Isymb2e :: Symbol -> Exp Symbol type instance Eval (Isymb2e s) = Eval (If (IsIsymb @@ s) (Pure "e") (Pure s) ) :}
>>>
:kind! Eval (FMap Isymb2e ('Text "imu"))
Eval (FMap Isymb2e ('Text "imu")) :: Text = 'Text "emu"
data Intercalate :: Text -> [Text] -> Exp Text Source #
Intercalate for type-level text.
Example
>>>
:kind! Eval (Intercalate ('Text " & ") ('[ 'Text "aamu", 'Text "valo"]))
Eval (Intercalate ('Text " & ") ('[ 'Text "aamu", 'Text "valo"])) :: Text = 'Text "aamu & valo"
Instances
type Eval (Intercalate txt txts :: Text -> Type) Source # | |
Defined in Fcf.Data.Text |
data Intersperse :: Symbol -> Text -> Exp Text Source #
Intersperse for type-level text.
Example
>>>
:kind! Eval (Intersperse "." ('Text "aamu"))
Eval (Intersperse "." ('Text "aamu")) :: Text = 'Text "a.a.m.u"
Instances
type Eval (Intersperse s ('Text txt) :: Text -> Type) Source # | |
Defined in Fcf.Data.Text type Eval (Intersperse s ('Text txt) :: Text -> Type) = Eval (FromSymbolList =<< Intersperse s (ToList txt)) |
data Reverse :: Text -> Exp Text Source #
Reverse for type-level text.
Example
>>>
:kind! Eval (Reverse ('Text "aamu"))
Eval (Reverse ('Text "aamu")) :: Text = 'Text "umaa"
>>>
:kind! Eval (Reverse =<< Reverse ('Text "aamu"))
Eval (Reverse =<< Reverse ('Text "aamu")) :: Text = 'Text "aamu"
data Replace :: Text -> Text -> Text -> Exp Text Source #
Replace for type-level text.
Example
>>>
:kind! Eval (Replace ('Text "tu") ('Text "la") ('Text "tuututtaa"))
Eval (Replace ('Text "tu") ('Text "la") ('Text "tuututtaa")) :: Text = 'Text "laulattaa"
Special Folds
data Concat :: [Text] -> Exp Text Source #
Concat for type-level text.
Example
>>>
:kind! Eval (Concat '[ 'Text "la", 'Text "kana"])
Eval (Concat '[ 'Text "la", 'Text "kana"]) :: Text = 'Text "lakana"
data FConcatMap :: (Symbol -> Exp Text) -> Text -> Exp Text Source #
FConcatMap for type-level text.
Example
>>>
:{
data IsIsymb :: Symbol -> Exp Bool type instance Eval (IsIsymb s) = Eval ("i" S.== s) data Isymb2aa :: Symbol -> Exp Text type instance Eval (Isymb2aa s) = Eval (If (IsIsymb @@ s) (Pure ('Text "aa")) (Pure ('Text s)) ) :}
>>>
:kind! Eval (FConcatMap Isymb2aa ('Text "imu ih"))
Eval (FConcatMap Isymb2aa ('Text "imu ih")) :: Text = 'Text "aamu aah"
data Any :: (Symbol -> Exp Bool) -> Text -> Exp Bool Source #
Any for type-level text.
Example
>>>
:kind! Eval (Any S.IsDigit ('Text "aamu1"))
Eval (Any S.IsDigit ('Text "aamu1")) :: Bool = 'True
>>>
:kind! Eval (Any S.IsDigit ('Text "aamu"))
Eval (Any S.IsDigit ('Text "aamu")) :: Bool = 'False
data All :: (Symbol -> Exp Bool) -> Text -> Exp Bool Source #
All for type-level text.
Example
>>>
:kind! Eval (All S.IsDigit ('Text "aamu1"))
Eval (All S.IsDigit ('Text "aamu1")) :: Bool = 'False
>>>
:kind! Eval (All S.IsDigit ('Text "321"))
Eval (All S.IsDigit ('Text "321")) :: Bool = 'True
Substrings
data Take :: Nat -> Text -> Exp Text Source #
Take for type-level text.
Example
>>>
:kind! Eval (Take 4 ('Text "aamun"))
Eval (Take 4 ('Text "aamun")) :: Text = 'Text "aamu"
data TakeEnd :: Nat -> Text -> Exp Text Source #
TakeEnd for type-level text.
Example
>>>
:kind! Eval (TakeEnd 4 ('Text "haamu"))
Eval (TakeEnd 4 ('Text "haamu")) :: Text = 'Text "aamu"
data Drop :: Nat -> Text -> Exp Text Source #
Drop for type-level text.
Example
>>>
:kind! Eval (Drop 2 ('Text "aamuna"))
Eval (Drop 2 ('Text "aamuna")) :: Text = 'Text "muna"
data DropEnd :: Nat -> Text -> Exp Text Source #
DropEnd for type-level text.
Example
>>>
:kind! Eval (DropEnd 2 ('Text "aamuna"))
Eval (DropEnd 2 ('Text "aamuna")) :: Text = 'Text "aamu"
data TakeWhile :: (Symbol -> Exp Bool) -> Text -> Exp Text Source #
TakeWhile for type-level text.
Example
>>>
:kind! Eval (TakeWhile (Not <=< S.IsDigit) ('Text "aamu12"))
Eval (TakeWhile (Not <=< S.IsDigit) ('Text "aamu12")) :: Text = 'Text "aamu"
data TakeWhileEnd :: (Symbol -> Exp Bool) -> Text -> Exp Text Source #
TakeWhileEnd for type-level text.
Example
>>>
:kind! Eval (TakeWhileEnd (Not <=< S.IsDigit) ('Text "12aamu"))
Eval (TakeWhileEnd (Not <=< S.IsDigit) ('Text "12aamu")) :: Text = 'Text "aamu"
data DropWhile :: (Symbol -> Exp Bool) -> Text -> Exp Text Source #
DropWhile for type-level text.
Example
>>>
:kind! Eval (DropWhile S.IsDigit ('Text "12aamu"))
Eval (DropWhile S.IsDigit ('Text "12aamu")) :: Text = 'Text "aamu"
data DropWhileEnd :: (Symbol -> Exp Bool) -> Text -> Exp Text Source #
DropWhileEnd for type-level text. === Example
>>>
:kind! Eval (DropWhileEnd S.IsDigit ('Text "aamu12"))
Eval (DropWhileEnd S.IsDigit ('Text "aamu12")) :: Text = 'Text "aamu"
data DropAround :: (Symbol -> Exp Bool) -> Text -> Exp Text Source #
DropAround for type-level text.
Example
>>>
:kind! Eval (DropAround S.IsDigit ('Text "34aamu12"))
Eval (DropAround S.IsDigit ('Text "34aamu12")) :: Text = 'Text "aamu"
Instances
type Eval (DropAround f txt :: Text -> Type) Source # | |
Defined in Fcf.Data.Text |
data Strip :: Text -> Exp Text Source #
Strip the space, newline and tab -symbols from the beginning and and of type-level text.
Example
>>>
:kind! Eval (Strip ('Text " aamu \n"))
Eval (Strip ('Text " aamu \n")) :: Text = 'Text "aamu"
Breaking etc
data SplitOn :: Text -> Text -> Exp [Text] Source #
SplitOn for type-level text.
Example
>>>
:kind! Eval (SplitOn ('Text "ab") ('Text "cdabfgabh"))
Eval (SplitOn ('Text "ab") ('Text "cdabfgabh")) :: [Text] = '[ 'Text "cd", 'Text "fg", 'Text "h"]
data Split :: (Symbol -> Exp Bool) -> Text -> Exp [Text] Source #
Split for type-level text.
Example
>>>
:kind! Eval (Split S.IsSpace (Eval (Singleton "cd bf abh")))
Eval (Split S.IsSpace (Eval (Singleton "cd bf abh"))) :: [Text] = '[ 'Text "cd", 'Text "bf", 'Text "abh"]
data Lines :: Text -> Exp [Text] Source #
Lines for type-level text.
Example
>>>
:kind! Eval (Lines =<< Singleton "ok\nhmm\nab")
Eval (Lines =<< Singleton "ok\nhmm\nab") :: [Text] = '[ 'Text "ok", 'Text "hmm", 'Text "ab"]
data Words :: Text -> Exp [Text] Source #
Words for type-level text.
Example
>>>
:kind! Eval (Words =<< Singleton "ok hmm\nab")
Eval (Words =<< Singleton "ok hmm\nab") :: [Text] = '[ 'Text "ok", 'Text "hmm", 'Text "ab"]
data Unlines :: [Text] -> Exp Text Source #
Unlines for type-level text. This adds a newline to each Text and then concats them.
Example
>>>
:kind! Eval (Unlines '[ 'Text "ok", 'Text "hmm", 'Text "ab"])
Eval (Unlines '[ 'Text "ok", 'Text "hmm", 'Text "ab"]) :: Text = 'Text "ok\nhmm\nab\n"
data Unwords :: [Text] -> Exp Text Source #
Unwords for type-level text. This uses Intercalate
to add space-symbol
between the given texts.
Example
>>>
:kind! Eval (Unwords '[ 'Text "ok", 'Text "hmm", 'Text "ab"])
Eval (Unwords '[ 'Text "ok", 'Text "hmm", 'Text "ab"]) :: Text = 'Text "ok hmm ab"
Predicates
data IsPrefixOf :: Text -> Text -> Exp Bool Source #
IsPrefixOf for type-level text.
Example
>>>
:kind! Eval (IsPrefixOf ('Text "aa") ('Text "aamiainen"))
Eval (IsPrefixOf ('Text "aa") ('Text "aamiainen")) :: Bool = 'True
Instances
type Eval (IsPrefixOf ('Text l1) ('Text l2) :: Bool -> Type) Source # | |
Defined in Fcf.Data.Text type Eval (IsPrefixOf ('Text l1) ('Text l2) :: Bool -> Type) = Eval (IsPrefixOf (ToList l1) (ToList l2)) |
data IsSuffixOf :: Text -> Text -> Exp Bool Source #
IsSuffixOf for type-level text.
Example
>>>
:kind! Eval (IsSuffixOf ('Text "nen") ('Text "aamiainen"))
Eval (IsSuffixOf ('Text "nen") ('Text "aamiainen")) :: Bool = 'True
Instances
type Eval (IsSuffixOf ('Text l1) ('Text l2) :: Bool -> Type) Source # | |
Defined in Fcf.Data.Text type Eval (IsSuffixOf ('Text l1) ('Text l2) :: Bool -> Type) = Eval (IsSuffixOf (ToList l1) (ToList l2)) |