File: LineNo.hs

package info (click to toggle)
haskell-regex 1.1.0.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 424 kB
  • sloc: haskell: 4,533; makefile: 3
file content (21 lines) | stat: -rw-r--r-- 538 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Text.RE.ZeInternals.Types.LineNo where


-- | our line numbers are of the proper zero-based kind
newtype LineNo =
    ZeroBasedLineNo { getZeroBasedLineNo :: Int }
  deriving (Show,Enum)

-- | the first line in a file
firstLine :: LineNo
firstLine = ZeroBasedLineNo 0

-- | extract a conventional 1-based line number
getLineNo :: LineNo -> Int
getLineNo = succ . getZeroBasedLineNo

-- | inject a conventional 1-based line number
lineNo :: Int -> LineNo
lineNo = ZeroBasedLineNo . pred