From ed4e0ed06f9110a90d62bd85e7701a2b48a5e5f9 Mon Sep 17 00:00:00 2001 From: John Millikin Date: Thu, 17 Feb 2011 08:23:29 -0800 Subject: [PATCH] Add ``Ord`` instances for ``Instruction``, ``Name``, and ``Doctype``. --- Data/XML/Types.hs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/Data/XML/Types.hs b/Data/XML/Types.hs index f46ee79..432f8bc 100644 --- a/Data/XML/Types.hs +++ b/Data/XML/Types.hs @@ -62,6 +62,7 @@ import Control.Monad ((>=>)) import Data.Text.Lazy (Text) import qualified Data.Text.Lazy as T import Data.String (IsString, fromString) +import Data.Function (on) data Document = Document { documentPrologue :: Prologue @@ -81,7 +82,7 @@ data Instruction = Instruction { instructionTarget :: Text , instructionData :: Text } - deriving (Show, Eq) + deriving (Show, Eq, Ord) data Miscellaneous = MiscInstruction Instruction @@ -113,11 +114,6 @@ data Content | ContentEntity Text deriving (Show, Eq) --- | The 'Eq' instance for 'Name' ignores prefixes. --- --- The 'IsString' instance for 'Name' allows entry using Clark notation; --- see and --- data Name = Name { nameLocalName :: Text , nameNamespace :: Maybe Text @@ -125,13 +121,20 @@ data Name = Name } deriving (Show) --- Ignore prefixes when comparing names +-- | Ignores prefixes instance Eq Name where - x == y = and - [ nameLocalName x == nameLocalName y - , nameNamespace x == nameNamespace y - ] + (==) = (==) `on` (\x -> (nameNamespace x, nameLocalName x)) + +-- | Ignores prefixes +-- +-- Since 0.1.3 +instance Ord Name where + compare = compare `on` (\x -> (nameNamespace x, nameLocalName x)) +-- | Supports Clark notation; see and +-- +-- +-- Since 0.1.2 instance IsString Name where fromString "" = Name T.empty Nothing Nothing fromString full@('{':rest) = case break (== '}') rest of @@ -155,10 +158,14 @@ data Doctype = Doctype } deriving (Show, Eq) +-- | Since 0.1.3 +instance Ord Doctype where + compare = compare `on` (\x -> (doctypeName x, doctypeExternalID x)) + data ExternalID = SystemID Text | PublicID Text Text - deriving (Show, Eq) + deriving (Show, Eq, Ord) data InternalSubset = InternalSubset -- TODO -- 2.45.2