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

  • 2 types
  • 10 values
  • Packagetext-rope-0.2
  • Exports12
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceInternal.hs
datadata TextLines
#

A wrapper around Text for fast line/column navigation. Concatenation takes linear time.

This is a building block for Rope, which provides logarithmic concatenation.

Instances7Eq, Ord, Show, IsString, Semigroup, Monoid, …

Lines

3 declarations
valuelines :: TextLines -> [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 :: TextLines -> Word
#

Equivalent to Data.List.length . lines, but in O(1).

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

Split at given line, O(1).

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 :: TextLines -> Word
#

Length in UTF-16 code units. Takes linear time.

Example3 expressions
:set -XOverloadedStringslength "fя𐀀"4Data.Text.Lines.length "fя𐀀"3

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. Time is proportional to the length of the last line.

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. If requested number of code units splits a code point in half, return Nothing. Time is linear in posColumn, but does not depend on 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𐀀","я")