Last active
October 28, 2015 20:33
-
-
Save dball/63770f892bdba461ddfb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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