Skip to content

Optimize instance Ord of SourcePos #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Text/Parsec/Pos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ type Column = Int
-- 'Ord' class.

data SourcePos = SourcePos SourceName !Line !Column
deriving ( Eq, Ord, Data, Typeable)
deriving (Eq, Data, Typeable)

-- | The ordering compares first by line, column, then by sourcename.
instance Ord SourcePos where
compare (SourcePos snA lnA colA) (SourcePos snB lnB colB)
= lnA `compare` lnB <> colA `compare` colB <> snA `compare` snB

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