Created
December 12, 2016 15:12
-
-
Save shonfeder/60f2d4aaf04e8ff20ddef53f5ba575aa to your computer and use it in GitHub Desktop.
Cyclical data structure, I saw this on some SO answer
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
class (Enum a, Bounded a, Eq a) => Cyclical a where | |
next :: a -> a | |
next a = if a == maxBound then minBound else succ a | |
prev :: a -> a | |
prev a = if a == minBound then maxBound else pred a | |
data Direction = North | East | South | West | |
deriving (Show, Enum, Bounded, Eq) | |
instance Cyclical Direction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment