HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduletext-rope-0.2Haskell2010

Data.Text.Utf16.Rope.Mixed

  • 1 type
  • 16 values
  • Packagetext-rope-0.2
  • Exports17
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceMixed.hs
datadata Rope
#

Rope of Text chunks with logarithmic concatenation. This rope offers two interfaces: one based on code points and another one based on UTF-16 code units. This comes with a price of double bookkeeping and is less performant than Data.Text.Rope or Data.Text.Utf16.Rope.

Instances7Eq, Ord, Show, IsString, Semigroup, Monoid, …
  • Eq RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope.Mixed
  • Ord RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope.Mixed
  • Show RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope.Mixed
  • IsString RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope.Mixed
  • Semigroup RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope.Mixed
  • Monoid RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope.Mixed
  • NFData RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope.Mixed
valuenull :: Rope -> Bool
#

Check whether a rope is empty, O(1).

Lines

3 declarations
valuelines :: Rope -> [Text]
#

Split into lines by \n, similar to Data.Text.lines. Each line is produced in O(1).

Example6 expressions
:set -XOverloadedStringslines ""[]lines "foo"["foo"]lines "foo\n"["foo"]lines "foo\n\n"["foo",""]lines "foo\nbar"["foo","bar"]
valuelengthInLines :: Rope -> Word
#

Equivalent to Data.List.length . lines, but in logarithmic time.

Example6 expressions
:set -XOverloadedStringslengthInLines ""0lengthInLines "foo"1lengthInLines "foo\n"1lengthInLines "foo\n\n"2lengthInLines "foo\nbar"2

If you do not care about ignoring the last newline character, you can use posLine . charLengthAsPosition instead, which works in O(1).

valuesplitAtLine :: Word -> Rope -> (Rope, Rope)
#

Split at given line, logarithmic time.

Example2 expressions
:set -XOverloadedStringsmap (\l -> splitAtLine l "foo\nbar") [0..3][("","foo\nbar"),("foo\n","bar"),("foo\nbar",""),("foo\nbar","")]

Code points

4 declarations
valuecharLength :: Rope -> Word
#

Length in code points, similar to Data.Text.length, O(1).

Example2 expressions
:set -XOverloadedStringscharLength "fя𐀀"3
valuecharSplitAt :: Word -> Rope -> (Rope, Rope)
#

Split at given code point, similar to Data.Text.splitAt. Takes linear time.

Example2 expressions
:set -XOverloadedStringsmap (\c -> charSplitAt c "fя𐀀") [0..4][("","fя𐀀"),("f","я𐀀"),("fя","𐀀"),("fя𐀀",""),("fя𐀀","")]

Measure text length as an amount of lines and columns, O(1).

Example4 expressions
:set -XOverloadedStringscharLengthAsPosition "f𐀀"Position {posLine = 0, posColumn = 2}charLengthAsPosition "f\n𐀀"Position {posLine = 1, posColumn = 1}charLengthAsPosition "f\n𐀀\n"Position {posLine = 2, posColumn = 0}

Combination of splitAtLine and subsequent charSplitAt. Time is linear in posColumn and logarithmic in posLine.

Example7 expressions
:set -XOverloadedStringscharSplitAtPosition (Position 1 0) "f\n𐀀я"("f\n","𐀀я")charSplitAtPosition (Position 1 1) "f\n𐀀я"("f\n𐀀","я")charSplitAtPosition (Position 1 2) "f\n𐀀я"("f\n𐀀я","")charSplitAtPosition (Position 0 2) "f\n𐀀я"("f\n","𐀀я")charSplitAtPosition (Position 0 3) "f\n𐀀я"("f\n𐀀","я")charSplitAtPosition (Position 0 4) "f\n𐀀я"("f\n𐀀я","")

UTF-16 code units

4 declarations
valueutf16Length :: Rope -> Word
#

Length in UTF-16 code units, O(1).

Example2 expressions
:set -XOverloadedStringsutf16Length "fя𐀀"4
valueutf16SplitAt :: Word -> Rope -> Maybe (Rope, Rope)
#

Split at given UTF-16 code unit. If requested number of code units splits a code point in half, return Nothing. Takes linear time.

Example2 expressions
:set -XOverloadedStringsmap (\c -> utf16SplitAt c "fя𐀀") [0..4][Just ("","fя𐀀"),Just ("f","я𐀀"),Just ("fя","𐀀"),Nothing,Just ("fя𐀀","")]

Measure text length as an amount of lines and columns, O(1).

Example4 expressions
:set -XOverloadedStringsutf16LengthAsPosition "f𐀀"Position {posLine = 0, posColumn = 3}utf16LengthAsPosition "f\n𐀀"Position {posLine = 1, posColumn = 2}utf16LengthAsPosition "f\n𐀀\n"Position {posLine = 2, posColumn = 0}

Combination of splitAtLine and subsequent utf16SplitAt. Time is linear in posColumn and logarithmic in posLine.

Example7 expressions
:set -XOverloadedStringsutf16SplitAtPosition (Position 1 0) "f\n𐀀я"Just ("f\n","𐀀я")utf16SplitAtPosition (Position 1 1) "f\n𐀀я"Nothingutf16SplitAtPosition (Position 1 2) "f\n𐀀я"Just ("f\n𐀀","я")utf16SplitAtPosition (Position 0 2) "f\n𐀀я"Just ("f\n","𐀀я")utf16SplitAtPosition (Position 0 3) "f\n𐀀я"Nothingutf16SplitAtPosition (Position 0 4) "f\n𐀀я"Just ("f\n𐀀","я")