Created
November 26, 2020 22:51
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
data CharacteristicType = DiffPresent | DiffData | |
deriving (Show, Eq) | |
type family DiffType (t :: CharacteristicType) where | |
DiffType 'DiffPresent = Bool | |
DiffType 'DiffData = Maybe LevelData | |
data LevelInfo t = (Show (DiffType t), Eq (DiffType t), FromJSON (DiffType t)) => | |
LevelInfo | |
{ _infoEasy :: DiffType t | |
, _infoNormal :: DiffType t | |
, _infoHard :: DiffType t | |
, _infoExpert :: DiffType t | |
, _infoExpertPlus :: DiffType t | |
} | |
deriving instance Show (LevelInfo t) | |
deriving instance Eq (LevelInfo t) | |
instance FromJSON (LevelInfo 'DiffPresent) where | |
parseJSON = withObject "difficulties" $ \o -> do | |
LevelInfo <$> o .: "easy" | |
<*> o .: "normal" | |
<*> o .: "hard" | |
<*> o .: "expert" | |
<*> o .: "expertPlus" | |
instance FromJSON (LevelInfo 'DiffData) where | |
parseJSON = withObject "difficulties" $ \o -> do | |
LevelInfo <$> o .: "easy" | |
<*> o .: "normal" | |
<*> o .: "hard" | |
<*> o .: "expert" | |
<*> o .: "expertPlus" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment