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

Moduletext-rope-0.2Haskell2010

Data.Text.Utf16.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 UTF-16 code units. Use Data.Text.Rope, if you need code points, 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.Utf16.Rope
  • Ord RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope
  • Show RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope
  • IsString RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope
  • Semigroup RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope
  • Monoid RopeDefined in text-rope-0.2 · Data.Text.Utf16.Rope
  • NFData RopeDefined in text-rope-0.2 · Data.Text.Utf16.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","")]

UTF-16 code units

5 declarations
valuelength :: Rope -> Word
#

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

Example3 expressions
:set -XOverloadedStringslength "fя𐀀"4Data.Text.Rope.length "fя𐀀"3
valuesplitAt :: 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 -> splitAt c "fя𐀀") [0..4][Just ("","fя𐀀"),Just ("f","я𐀀"),Just ("fя","𐀀"),Nothing,Just ("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.Utf16.Lines
  • Ord PositionDefined in text-rope-0.2 · Data.Text.Utf16.Lines
  • Show PositionDefined in text-rope-0.2 · Data.Text.Utf16.Lines
  • Semigroup PositionDefined in text-rope-0.2 · Data.Text.Utf16.Lines

    Associativity does not hold when posLine overflows.

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

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

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

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

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