Skip to content

Instantly share code, notes, and snippets.

@mvaldesdeleon
Created December 26, 2018 15:56
Show Gist options
  • Save mvaldesdeleon/cf109f3fdab69f2c93c1c9ab2d11961e to your computer and use it in GitHub Desktop.
Save mvaldesdeleon/cf109f3fdab69f2c93c1c9ab2d11961e to your computer and use it in GitHub Desktop.
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