Reputation: 546
Is there anyway I can adjust the Ord
(order) of regular characters in a Haskell program such that 'a' > 'b'
?
If not, do y'all have any suggestions on how I can best replicate this functionality? I tried Data magicLetters = 'b' | 'a' | 'c' deriving (Show, Ord)
, but didn't get very far with that syntax.
Upvotes: 3
Views: 175
Reputation: 34292
Depending on why and how you're going to use it, you can try a wrapper-type:
newtype MyChar = MyChar Char
instance Eq MyChar where
MyChar x == MyChar y = x == y
instance Ord MyChar where
MyChar x <= MyChar y = x >= y -- reverses the order
If you need a more specific logic, like a > b
, but b < c
, you may need some ordering table.
EDIT: As @leftaroundabout points out, the above already exists as Down
Upvotes: 10