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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With