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.Rope

  • 2 types
  • 12 values
  • Packagetext-rope-0.2
  • Exports14
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceRope.hs
datadata Rope
#

Rope of Text chunks with logarithmic concatenation. This rope offers an interface, based on code points. Use Data.Text.Utf16.Rope, if you need UTF-16 code units, or Data.Text.Utf16.Rope.Mixed, if you need both interfaces.

Instances7Eq, Ord, Show, IsString, Semigroup, Monoid, …
  • Eq RopeDefined in text-rope-0.2 · Data.Text.Rope
  • Ord RopeDefined in text-rope-0.2 · Data.Text.Rope
  • Show RopeDefined in text-rope-0.2 · Data.Text.Rope
  • IsString RopeDefined in text-rope-0.2 · Data.Text.Rope
  • Semigroup RopeDefined in text-rope-0.2 · Data.Text.Rope
  • Monoid RopeDefined in text-rope-0.2 · Data.Text.Rope
  • NFData RopeDefined in text-rope-0.2 · Data.Text.Rope
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 . lengthAsPosition 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

5 declarations
valuelength :: Rope -> Word
#

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

Example3 expressions
:set -XOverloadedStringslength "fя𐀀"3Data.Text.Utf16.Rope.length "fя𐀀"4
valuesplitAt :: Word -> Rope -> (Rope, Rope)
#

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

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

Represent a position in a text.

Constructors

Instances6Eq, Ord, Show, Semigroup, Monoid, NFData
  • Eq PositionDefined in text-rope-0.2 · Data.Text.Lines.Internal
  • Ord PositionDefined in text-rope-0.2 · Data.Text.Lines.Internal
  • Show PositionDefined in text-rope-0.2 · Data.Text.Lines.Internal
  • Semigroup PositionDefined in text-rope-0.2 · Data.Text.Lines.Internal

    Associativity does not hold when posLine overflows.

  • Monoid PositionDefined in text-rope-0.2 · Data.Text.Lines.Internal
  • NFData PositionDefined in text-rope-0.2 · Data.Text.Lines.Internal

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

Example4 expressions
:set -XOverloadedStringslengthAsPosition "f𐀀"Position {posLine = 0, posColumn = 2}lengthAsPosition "f\n𐀀"Position {posLine = 1, posColumn = 1}lengthAsPosition "f\n𐀀\n"Position {posLine = 2, posColumn = 0}
valuesplitAtPosition :: Position -> Rope -> (Rope, Rope)
#

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

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