Last active
August 29, 2015 14:23
-
-
Save taksuyu/fb11a0e494f4defe0a7f 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
-- | When dealing with multiple sets, you can have different | |
-- constraints. This can be observed in Mahjong where Suits will have | |
-- nine different values, but honors will vary. Wind and Dragon for | |
-- example have four and three values respectfully. They also don't | |
-- fit in with Bounded because these concepts exist together at the | |
-- same time and need to be handled differently. In many circumstances | |
-- you can define `minBoundBy` and `maxBoundBy` as just `minBound` and | |
-- `maxBound`. | |
class Bounded b => BoundedBy a b where | |
minBoundBy :: a -> b | |
minBoundBy _ = minBound | |
maxBoundBy :: a -> b | |
maxBoundBy _ = maxBound | |
data Suits = Character | |
| Circle | |
| Bamboo | |
deriving (Eq, Show) | |
instance BoundedBy Suits SNum | |
data SNum = One | |
| Two | |
| Three | |
| Four | |
| Five | |
| Six | |
| Seven | |
| Eight | |
| Nine | |
deriving (Eq, Ord, Enum, Bounded, Show) | |
test_minBoundBy :: Suits -> SNum | |
test_minBoundBy = minBoundBy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment