Skip to content

Instantly share code, notes, and snippets.

@shonfeder
Created December 12, 2016 15:12
Show Gist options
  • Save shonfeder/60f2d4aaf04e8ff20ddef53f5ba575aa to your computer and use it in GitHub Desktop.
Save shonfeder/60f2d4aaf04e8ff20ddef53f5ba575aa to your computer and use it in GitHub Desktop.
Cyclical data structure, I saw this on some SO answer
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