Skip to content

Instantly share code, notes, and snippets.

@incertia
Created November 26, 2020 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incertia/3df23f63d1e4b17bfd5eaa6c16953fc0 to your computer and use it in GitHub Desktop.
Save incertia/3df23f63d1e4b17bfd5eaa6c16953fc0 to your computer and use it in GitHub Desktop.
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