Created
December 26, 2018 15:56
-
-
Save mvaldesdeleon/cf109f3fdab69f2c93c1c9ab2d11961e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Position = Position | |
{ _x :: Integer | |
, _y :: Integer | |
} deriving (Show, Eq) | |
-- We want to sort by Y first, and then by X, so we need a custom Ord instance | |
instance Ord Position where | |
Position x0 y0 <= Position x1 y1 = | |
if y0 /= y1 | |
then y0 <= y1 | |
else x0 <= x1 | |
-- Or we can rearrange the internal structure of our Record | |
data Position' = Position' | |
{ _y :: Integer | |
, _x :: Integer | |
} deriving (Show, Eq, Ord) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment