HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulefcf-containers-0.8.2Haskell2010

Fcf.Data.NewText

Fcf.Data.NewText

We mimick Data.Text but on type level. The current internal representation of Fcf.Data.Text is based on type level lists. The current (as of early 2023) implementation of this Fcf.Data.Text will be deprecated and replaced with the contents of Fcf.Data.NewText later 2023 as newer version GHC become more widespread.

The old version working with 9.0.x or less will be kept at Fcf.Data.OldText for some time. Similarly, the module Fcf.Data.NewText contains the functions and definitions for better Text type, which will be taken into use after some time.

The Fcf.Data.NewText will replace Fcf.Data.Text eventually.

  • 63 types
datadata Text
#

Text is a data structure, that is, a list to hold type-level symbols of length one.

Constructors

Instances51KnownVal, Eval, …

Creation

9 declarations
datadata Empty (a :: Text)
#

Empty

Example
Example1 expression
:kind! (Eval Empty :: Text)(Eval Empty :: Text) :: Text= 'Text ""

See also the other examples in this module.

Instances1Eval
  • type Eval Empty = 'Text ""Defined in fcf-containers-0.8.2 · Fcf.Data.NewText
datadata FromSymbolList (a :: [Symbol]) (b :: Text)
#

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"

Instances1Eval
datadata FromSymbol (a :: Symbol) (b :: Text)
#

FromSymbol

Example
Example1 expression
:kind! Eval (FromSymbol "some text")Eval (FromSymbol "some text") :: Text= 'Text "some text"
Instances1Eval
datadata ToList (a :: Text) (b :: [Text])
#

Split text to characters and give them as Text list.

:kind! Eval (ToList =<< FromSymbol "abc")

Eval (ToList =<< FromSymbol "abc") :: [Text] = '[ 'Text "a", 'Text "b", 'Text "c"]

Instances1Eval
datadata ToSymbolList (a :: Text) (b :: [Symbol])
#

Get the type-level list out of the Text.

Example
Example1 expression
:kind! Eval (ToSymbolList =<< FromSymbolList '["a", "b"])Eval (ToSymbolList =<< FromSymbolList '["a", "b"]) :: [Symbol]= '["a", "b"]
Instances1Eval
datadata ToCharList (a :: Text) (b :: [Char])
#

Split text to characters and give them as Char list.

:kind! Eval (ToCharList =<< FromSymbol "abc")

Eval (ToCharList =<< FromSymbol "abc") :: [Char] = '[a, b, c]

Instances1Eval
datadata Unpack (a :: Text) (b :: Symbol)
#

Unpack

Example
Example1 expression
:kind! Eval (Unpack =<< FromSymbol "word")Eval (Unpack =<< FromSymbol "word") :: Symbol= "word"
Instances1Eval
  • type Eval (Unpack ('Text sym)) = symDefined in fcf-containers-0.8.2 · Fcf.Data.NewText

Basic Interface

14 declarations
datadata Null (a :: Text) (b :: Bool)
#

Null

Example
Example1 expression
:kind! Eval (Null ('Text "ab"))Eval (Null ('Text "ab")) :: Bool= 'False
Example1 expression
:kind! Eval (Null =<< Empty)Eval (Null =<< Empty) :: Bool= 'True
Instances1Eval
datadata Length (a :: Text) (b :: Nat)
#

Length

Example
Example1 expression
:kind! Eval (Length =<< FromSymbol "ab")Eval (Length =<< FromSymbol "ab") :: TL.Natural= 2
Instances1Eval
datadata Append (a :: Text) (b :: Text) (c :: Text)
#

Append two type-level texts.

Example
Example1 expression
:kind! Eval (Append ('Text "aa") ('Text "mu"))Eval (Append ('Text "aa") ('Text "mu")) :: Text= 'Text "aamu"
Instances1Eval
datadata Cons (a :: Char) (b :: Text) (c :: Text)
#

Add a Char to the beginning of a type-level text.

Example
Example1 expression
:kind! Eval (Cons 'h' ('Text "aamu"))Eval (Cons 'h' ('Text "aamu")) :: Text= 'Text "haamu"
Instances1Eval
datadata ConsSymbol (a :: Symbol) (b :: Text) (c :: Text)
#

Add a Symbol to the beginning of a type-level text.

Example
Example1 expression
:kind! Eval (ConsSymbol "h" ('Text "aamu"))Eval (ConsSymbol "h" ('Text "aamu")) :: Text= 'Text "haamu"
Instances1Eval
datadata Snoc (a :: Text) (b :: Char) (c :: Text)
#

Add a Char to the end of a type-level text.

Example
Example1 expression
:kind! Eval (Snoc ('Text "aam") 'u')Eval (Snoc ('Text "aam") 'u') :: Text= 'Text "aamu"
Instances1Eval
datadata SnocSymbol (a :: Text) (b :: Symbol) (c :: Text)
#

Add a Symbol to the end of a type-level text.

Example
Example1 expression
:kind! Eval (SnocSymbol ('Text "aam") "u")Eval (SnocSymbol ('Text "aam") "u") :: Text= 'Text "aamu"
Instances1Eval
datadata Uncons (a :: Text) (b :: Maybe (Char, Text))
#

Get the first Char from type-level text.

Example
Example1 expression
:kind! Eval (Uncons ('Text "haamu"))Eval (Uncons ('Text "haamu")) :: Maybe (Char, Text)= 'Just '('h', 'Text "aamu")
Example1 expression
:kind! Eval (Uncons ('Text ""))Eval (Uncons ('Text "")) :: Maybe (Char, Text)= 'Nothing
Instances1Eval
datadata Unsnoc (a :: Text) (b :: Maybe (Text, Char))
#

Get the last Char from type-level text.

Example
Example1 expression
:kind! Eval (Unsnoc ('Text "aamun"))Eval (Unsnoc ('Text "aamun")) :: Maybe (Text, Char)= 'Just '( 'Text "aamu", 'n')
Example1 expression
:kind! Eval (Unsnoc ('Text ""))Eval (Unsnoc ('Text "")) :: Maybe (Text, Char)= 'Nothing
Instances1Eval
datadata Head (a :: Text) (b :: Maybe Char)
#

Get the first Char of type-level text.

Example
Example1 expression
:kind! Eval (Head ('Text "aamu"))Eval (Head ('Text "aamu")) :: Maybe Char= 'Just 'a'
Example1 expression
:kind! Eval (Head ('Text ""))Eval (Head ('Text "")) :: Maybe Char= 'Nothing
Instances1Eval
datadata Last (a :: Text) (b :: Maybe Char)
#

Get the last Char of type-level text.

Example
Example1 expression
:kind! Eval (Last ('Text "aamu"))Eval (Last ('Text "aamu")) :: Maybe Char= 'Just 'u'
Example1 expression
:kind! Eval (Last ('Text ""))Eval (Last ('Text "")) :: Maybe Char= 'Nothing
Instances1Eval
datadata Tail (a :: Text) (b :: Maybe Text)
#

Get the tail of a type-level text.

Example
Example1 expression
:kind! Eval (Tail ('Text "haamu"))Eval (Tail ('Text "haamu")) :: Maybe Text= 'Just ('Text "aamu")
Example1 expression
:kind! Eval (Tail ('Text ""))Eval (Tail ('Text "")) :: Maybe Text= 'Nothing
Instances1Eval
datadata Init (a :: Text) (b :: Maybe Text)
#

Take all except the last Char from type-level text.

Example
Example1 expression
:kind! Eval (Init ('Text "aamun"))Eval (Init ('Text "aamun")) :: Maybe Text= 'Just ('Text "aamu")
Example1 expression
:kind! Eval (Init ('Text ""))Eval (Init ('Text "")) :: Maybe Text= 'Nothing
Instances1Eval
datadata CompareLength (a :: Text) (b :: Nat) (c :: Ordering)
#

Compare the length of type-level text to given Nat and give the Ordering.

Example
Example1 expression
:kind! Eval (CompareLength ('Text "aamu") 3)Eval (CompareLength ('Text "aamu") 3) :: Ordering= 'GT
Instances1Eval

Transformation

8 declarations
datadata FMap (a :: Char -> Exp Char) (b :: Text) (c :: Text)
#

FMap for type-level text.

Example
Example1 expression
:{data DigitsToX :: Char -> Exp Chartype instance Eval (DigitsToX c) = Eval    (If (IsDigit @@ c)        (Pure 'X')        (Pure c)    ):}
Example1 expression
:kind! Eval (FMap DigitsToX ('Text "Some4text5oh9."))Eval (FMap DigitsToX ('Text "Some4text5oh9.")) :: Text= 'Text "SomeXtextXohX."
Instances1Eval
datadata FMapSymbol (a :: Symbol -> Exp Symbol) (b :: Text) (c :: Text)
#

FMapSymbol for type-level text.

Example
Example1 expression
:{data IsIsymb :: Symbol -> Exp Booltype instance Eval (IsIsymb s) = Eval ("i" Sym.== s)data Isymb2e :: Symbol -> Exp Symboltype instance Eval (Isymb2e s) = Eval    (If (IsIsymb @@ s)        (Pure "e")        (Pure s)    ):}
Example1 expression
:kind! Eval (FMapSymbol Isymb2e ('Text "imu"))Eval (FMapSymbol Isymb2e ('Text "imu")) :: Text= 'Text "emu"
Instances1Eval
datadata Intercalate (a :: Text) (b :: [Text]) (c :: Text)
#

Intercalate for type-level text.

Example
Example1 expression
:kind! Eval (Intercalate ('Text " & ") ('[ 'Text "aamu", 'Text "valo"]))Eval (Intercalate ('Text " & ") ('[ 'Text "aamu", 'Text "valo"])) :: Text= 'Text "aamu & valo"
Instances1Eval
datadata Reverse (a :: Text) (b :: Text)
#

Reverse for type-level text.

Example
Example1 expression
:kind! Eval (Reverse ('Text "aamu"))Eval (Reverse ('Text "aamu")) :: Text= 'Text "umaa"
Example1 expression
:kind! Eval (Reverse =<< Reverse ('Text "aamu"))Eval (Reverse =<< Reverse ('Text "aamu")) :: Text= 'Text "aamu"
Instances1Eval
datadata Replace (a :: Text) (b :: Text) (c :: Text) (d :: Text)
#

Replace for type-level text.

Example
Example1 expression
:kind! Eval (Replace ('Text "tu") ('Text "la") ('Text "tuututtaa"))Eval (Replace ('Text "tu") ('Text "la") ('Text "tuututtaa")) :: Text= 'Text "laulattaa"
Instances1Eval

Special Folds

8 declarations
datadata Concat (a :: [Text]) (b :: Text)
#

Concat for type-level text.

Example
Example1 expression
:kind! Eval (Concat '[ 'Text "la", 'Text "kana"])Eval (Concat '[ 'Text "la", 'Text "kana"]) :: Text= 'Text "lakana"
Instances1Eval
datadata ConcatMap (a :: Char -> Exp Text) (b :: Text) (c :: Text)
#

ConcatMap for type-level text. This takes Char to Text function.

Example
Example1 expression
:{data DigitsToHoo :: Char -> Exp Texttype instance Eval (DigitsToHoo c) = Eval    (If (IsDigit @@ c)        (Pure ( 'Text "hoo"))        (Singleton c)    ):}
Example1 expression
:kind! Eval (ConcatMap DigitsToHoo ('Text "haa2hui2"))Eval (ConcatMap DigitsToHoo ('Text "haa2hui2")) :: Text= 'Text "haahoohuihoo"
Instances1Eval
datadata ConcatMapSymbol (a :: Symbol -> Exp Text) (b :: Text) (c :: Text)
#

FConcatMapSymbol for type-level text. This takes Symbol to Text function.

Example
Example1 expression
:{data IsIsymb :: Symbol -> Exp Booltype instance Eval (IsIsymb s) = Eval ("i" Sym.== s)data Isymb2aa :: Symbol -> Exp Texttype instance Eval (Isymb2aa s) = Eval    (If (IsIsymb @@ s)        (Pure ('Text "aa"))        (Pure ('Text s))    ):}
Example1 expression
:kind! Eval (ConcatMapSymbol Isymb2aa ('Text "imu ih"))Eval (ConcatMapSymbol Isymb2aa ('Text "imu ih")) :: Text= 'Text "aamu aah"
Instances1Eval
datadata Any (a :: Char -> Exp Bool) (b :: Text) (c :: Bool)
#

Any for type-level text. This takes Char to Bool function.

Example
Example1 expression
:kind! Eval (Any IsDigit ('Text "aamu1"))Eval (Any IsDigit ('Text "aamu1")) :: Bool= 'True
Example1 expression
:kind! Eval (Any IsDigit ('Text "aamu"))Eval (Any IsDigit ('Text "aamu")) :: Bool= 'False
Instances1Eval
datadata AnySymbol (a :: Symbol -> Exp Bool) (b :: Text) (c :: Bool)
#

AnySymbol for type-level text. This takes Symbol to Bool function. Note that the given function needs to be compatible... (i.e. operating with symbols of length 1.

Example
Example1 expression
:kind! Eval (AnySymbol Sym.IsDigit ('Text "aamu1"))Eval (AnySymbol Sym.IsDigit ('Text "aamu1")) :: Bool= 'True
Example1 expression
:kind! Eval (AnySymbol Sym.IsDigit ('Text "aamu"))Eval (AnySymbol Sym.IsDigit ('Text "aamu")) :: Bool= 'False
Instances1Eval
datadata All (a :: Char -> Exp Bool) (b :: Text) (c :: Bool)
#

All for type-level text. This takes Char to Bool function.

Example
Example1 expression
:kind! Eval (All IsDigit ('Text "aamu1"))Eval (All IsDigit ('Text "aamu1")) :: Bool= 'False
Example1 expression
:kind! Eval (All IsDigit ('Text "321"))Eval (All IsDigit ('Text "321")) :: Bool= 'True
Instances1Eval
datadata AllSymbol (a :: Symbol -> Exp Bool) (b :: Text) (c :: Bool)
#

AllSymbol for type-level text. This takes Symbol to Bool function.

Example
Example1 expression
:kind! Eval (AllSymbol Sym.IsDigit ('Text "aamu1"))Eval (AllSymbol Sym.IsDigit ('Text "aamu1")) :: Bool= 'False
Example1 expression
:kind! Eval (AllSymbol Sym.IsDigit ('Text "321"))Eval (AllSymbol Sym.IsDigit ('Text "321")) :: Bool= 'True
Instances1Eval

Substrings

14 declarations
datadata Take (a :: Nat) (b :: Text) (c :: Text)
#

Take for type-level text.

Example
Example1 expression
:kind! Eval (Take 4 ('Text "aamun"))Eval (Take 4 ('Text "aamun")) :: Text= 'Text "aamu"
Instances1Eval
datadata Drop (a :: Nat) (b :: Text) (c :: Text)
#

Drop for type-level text.

Example
Example1 expression
:kind! Eval (Drop 2 ('Text "aamuna"))Eval (Drop 2 ('Text "aamuna")) :: Text= 'Text "muna"
Instances1Eval
datadata TakeWhileEnd (a :: Char -> Exp Bool) (b :: Text) (c :: Text)
#

TakeWhileEnd for type-level text. This takes Char to Bool function.

Example
Example1 expression
:kind! Eval (TakeWhileEnd (Not <=< IsDigit) ('Text "12aamu"))Eval (TakeWhileEnd (Not <=< IsDigit) ('Text "12aamu")) :: Text= 'Text "aamu"
Instances1Eval
datadata TakeWhileEndSymbol (a :: Symbol -> Exp Bool) (b :: Text) (c :: Text)
#

TakeWhileEndSymbol for type-level text. This takes Symbol to Bool function.

Example
Example1 expression
:kind! Eval (TakeWhileEndSymbol (Not <=< Sym.IsDigit) ('Text "12aamu"))Eval (TakeWhileEndSymbol (Not <=< Sym.IsDigit) ('Text "12aamu")) :: Text= 'Text "aamu"
Instances1Eval
datadata DropAround (a :: Char -> Exp Bool) (b :: Text) (c :: Text)
#

DropAround for type-level text. This takes Char to Bool function.

Example
Example1 expression
:kind! Eval (DropAround IsDigit ('Text "34aamu12"))Eval (DropAround IsDigit ('Text "34aamu12")) :: Text= 'Text "aamu"
Instances1Eval
datadata DropAroundSymbol (a :: Symbol -> Exp Bool) (b :: Text) (c :: Text)
#

DropAroundSymbol for type-level text. This takes Symbol to Bool function.

Example
Example1 expression
:kind! Eval (DropAroundSymbol Sym.IsDigit ('Text "34aamu12"))Eval (DropAroundSymbol Sym.IsDigit ('Text "34aamu12")) :: Text= 'Text "aamu"
Instances1Eval
datadata Strip (a :: Text) (b :: Text)
#

Strip the space, newline and tab -symbols from the beginning and and of type-level text.

Example
Example1 expression
:kind! Eval (Strip ('Text "  aamu \n"))Eval (Strip ('Text "  aamu \n")) :: Text= 'Text "aamu"
Instances1Eval

Breaking etc

6 declarations
datadata Split (a :: Char -> Exp Bool) (b :: Text) (c :: [Text])
#

Split for type-level text. This takes Char to Bool function.

Example
Example1 expression
:kind! Eval (Split C.IsSpace (Eval (FromSymbol "cd bf abh")))Eval (Split C.IsSpace (Eval (FromSymbol "cd bf abh"))) :: [Text]= '[ 'Text "cd", 'Text "bf", 'Text "abh"]
Instances1Eval
datadata Lines (a :: Text) (b :: [Text])
#

Lines for type-level text.

Example
Example1 expression
:kind! Eval (Lines =<< FromSymbol "ok\nhmm\nab")Eval (Lines =<< FromSymbol "ok\nhmm\nab") :: [Text]= '[ 'Text "ok", 'Text "hmm", 'Text "ab"]
Instances1Eval
datadata Words (a :: Text) (b :: [Text])
#

Words for type-level text.

Example
Example1 expression
:kind! Eval (Words =<< FromSymbol "ok hmm\nab")Eval (Words =<< FromSymbol "ok hmm\nab") :: [Text]= '[ 'Text "ok", 'Text "hmm", 'Text "ab"]
Instances1Eval
datadata Unlines (a :: [Text]) (b :: Text)
#

Unlines for type-level text. This adds a newline to each Text and then concats them.

Example
Example1 expression
:kind! Eval (Unlines '[ 'Text "ok", 'Text "hmm", 'Text "ab"])Eval (Unlines '[ 'Text "ok", 'Text "hmm", 'Text "ab"]) :: Text= 'Text "ok\nhmm\nab\n"
Instances1Eval
datadata Unwords (a :: [Text]) (b :: Text)
#

Unwords for type-level text. This uses Intercalate to add space-symbol between the given texts.

Example
Example1 expression
:kind! Eval (Unwords '[ 'Text "ok", 'Text "hmm", 'Text "ab"])Eval (Unwords '[ 'Text "ok", 'Text "hmm", 'Text "ab"]) :: Text= 'Text "ok hmm ab"
Instances1Eval

Predicates

3 declarations
datadata IsPrefixOf (a :: Text) (b :: Text) (c :: Bool)
#

IsPrefixOf for type-level text.

Example
Example1 expression
:kind! Eval (IsPrefixOf ('Text "aa") ('Text "aamiainen"))Eval (IsPrefixOf ('Text "aa") ('Text "aamiainen")) :: Bool= 'True
Instances1Eval
datadata IsSuffixOf (a :: Text) (b :: Text) (c :: Bool)
#

IsSuffixOf for type-level text.

Example
Example1 expression
:kind! Eval (IsSuffixOf ('Text "nen") ('Text "aamiainen"))Eval (IsSuffixOf ('Text "nen") ('Text "aamiainen")) :: Bool= 'True
Instances1Eval
datadata IsInfixOf (a :: Text) (b :: Text) (c :: Bool)
#

IsInfixOf for type-level text.

Example
Example1 expression
:kind! Eval (IsInfixOf ('Text "mia") ('Text "aamiainen"))Eval (IsInfixOf ('Text "mia") ('Text "aamiainen")) :: Bool= 'True
Instances1Eval