Skip to content

Commit 7b8ea03

Browse files
Max Ulidtkoparsonsmatt
authored andcommitted
Optimise instance Ord of SourcePos
See issue haskell#171. Co-Authored-By: Matt Parsons <[email protected]>
1 parent c5add8b commit 7b8ea03

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Text/Parsec/Pos.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ type Column = Int
4141
-- 'Ord' class.
4242

4343
data SourcePos = SourcePos SourceName !Line !Column
44-
deriving ( Eq, Ord, Data, Typeable)
44+
deriving (Eq, Data, Typeable)
45+
46+
-- | The ordering compares first by line, column, then by sourcename.
47+
instance Ord SourcePos where
48+
compare (SourcePos snA lnA colA) (SourcePos snB lnB colB)
49+
= lnA `compare` lnB <> colA `compare` colB <> snA `compare` snB
4550

4651
-- | Create a new 'SourcePos' with the given source name,
4752
-- line number and column number.

0 commit comments

Comments
 (0)