loc-0.1.3.2: Types representing line and column positions and ranges in text files.

Safe HaskellNone
LanguageHaskell2010

Data.Loc.Pos

Contents

Synopsis

Documentation

data Pos Source #

Pos stands for positive integer. You can also think of it as position, because we use it to represent line and column numbers (Line and Column).

Pos has instances of several of the standard numeric typeclasses, although many of the operations throw Underflow when non-positive values result. Pos does not have an Integral instance, because there is no sensible way to implement quotRem.

Instances

Enum Pos Source #
>>> toEnum 3 :: Pos
3
>>> toEnum 0 :: Pos
*** Exception: arithmetic underflow
>>> fromEnum (3 :: Pos)
3

Methods

succ :: Pos -> Pos #

pred :: Pos -> Pos #

toEnum :: Int -> Pos #

fromEnum :: Pos -> Int #

enumFrom :: Pos -> [Pos] #

enumFromThen :: Pos -> Pos -> [Pos] #

enumFromTo :: Pos -> Pos -> [Pos] #

enumFromThenTo :: Pos -> Pos -> Pos -> [Pos] #

Eq Pos Source # 

Methods

(==) :: Pos -> Pos -> Bool #

(/=) :: Pos -> Pos -> Bool #

Num Pos Source #
>>> fromInteger 3 :: Pos
3
>>> fromInteger 0 :: Pos
*** Exception: arithmetic underflow
>>> 2 + 3 :: Pos
5
>>> 3 - 2 :: Pos
1
>>> 3 - 3 :: Pos
*** Exception: arithmetic underflow
>>> 2 * 3 :: Pos
6
>>> negate 3 :: Pos
*** Exception: arithmetic underflow

Methods

(+) :: Pos -> Pos -> Pos #

(-) :: Pos -> Pos -> Pos #

(*) :: Pos -> Pos -> Pos #

negate :: Pos -> Pos #

abs :: Pos -> Pos #

signum :: Pos -> Pos #

fromInteger :: Integer -> Pos #

Ord Pos Source # 

Methods

compare :: Pos -> Pos -> Ordering #

(<) :: Pos -> Pos -> Bool #

(<=) :: Pos -> Pos -> Bool #

(>) :: Pos -> Pos -> Bool #

(>=) :: Pos -> Pos -> Bool #

max :: Pos -> Pos -> Pos #

min :: Pos -> Pos -> Pos #

Read Pos Source # 
Real Pos Source # 

Methods

toRational :: Pos -> Rational #

Show Pos Source # 

Methods

showsPrec :: Int -> Pos -> ShowS #

show :: Pos -> String #

showList :: [Pos] -> ShowS #

ToNat Pos Source # 

Methods

toNat :: Pos -> Natural Source #

data Line Source #

Instances

class ToNat a where Source #

Types that can be converted to Natural.

This class mostly exists so that toNat can be used in situations that would normally call for toInteger (which we cannot use because Pos does not have an instance of Integral).

Minimal complete definition

toNat

Methods

toNat :: a -> Natural Source #

Show and Read

posShowsPrec :: Int -> Pos -> ShowS Source #

>>> posShowsPrec minPrec 1 ""
"1"
>>> posShowsPrec minPrec 42 ""
"42"

posReadPrec :: ReadPrec Pos Source #

>>> readPrec_to_S posReadPrec minPrec "1"
[(1,"")]
>>> readPrec_to_S posReadPrec minPrec "42"
[(42,"")]
>>> readPrec_to_S posReadPrec minPrec "0"
[]
>>> readPrec_to_S posReadPrec minPrec "-1"
[]