Skip to content

Instantly share code, notes, and snippets.

@dball
Last active October 28, 2015 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dball/63770f892bdba461ddfb to your computer and use it in GitHub Desktop.
Save dball/63770f892bdba461ddfb to your computer and use it in GitHub Desktop.
type Point a = (a, a)
type PointFn a = ((a -> a), (a -> a))
data Board a = Board { boardMin :: Point a,
boardMax :: Point a }
deriving (Show)
makeBoard :: (Enum a, Ord a) => Point Int -> Board a
makeBoard (x, y) = Board (z, z) (toEnum x, toEnum y)
where z = toEnum 0
neighborFns :: Enum a => [PointFn a]
neighborFns = [(pred, pred),
(pred, id),
(pred, succ),
(succ, pred),
(succ, id),
(succ, succ),
(id, succ),
(id, pred)]
neighbors :: (Enum a, Ord a) => Point a -> [Point a]
neighbors point = filter inBounds (map (applyNeighborFn point) neighborFns)
where applyNeighborFn (x, y) (fx, fy) = (fx x, fy y)
inBounds (x, y) = (x >= z) && (y >= z)
z = toEnum 0
inBounds (x, y) = (x >= z) && (y >= z)
z = toEnum 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment