Skip to content

Instantly share code, notes, and snippets.

@russmatney
Last active May 12, 2018 03:40
Show Gist options
  • Save russmatney/172cc7e401d07990f62dffd6b233ce3c to your computer and use it in GitHub Desktop.
Save russmatney/172cc7e401d07990f62dffd6b233ce3c to your computer and use it in GitHub Desktop.
-- | A newtype wrapper to force UserNames to be labeled, and prevent us from
-- passing the wrong type of name around.
newtype UserName = UserName Text deriving (Show, Eq)
newtype PetName = PetName Text deriving (Show, Eq)
-- | A type alias to improve the readability of our types.
-- An inventory is a HashMap with a Text key and Item value.
type Inventory = HM.HashMap Text Item
-- | A User record.
data User
= User
{ _userName :: UserName
, _userScore :: Int
, _userPet :: Maybe Pet
, _userInventory :: Inventory
} deriving (Show, Eq)
data Pet
= Pet
{ _petName :: PetName } deriving (Show, Eq)
-- | An Item record.
data Item
= Item
{ _itemValue :: Int
, _itemWeight :: Int
} deriving (Show, Eq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment