Hacker News new | ask | show | jobs
by eschew 3035 days ago
mkPlayer can be simplified further!

  mkPlayer :: Maybe Weapon -> Class -> Either Error Player

  mkPlayer (Just Staff) Warrior = Left "A Warrior cannot equip a Staff"
  mkPlayer (Just Sword) Wizard = Left "A Wizard cannot equip a Sword"
  mkPlayer weapon klass = Right (Player weapon klass)
1 comments

You lose exhaustiveness checks if new weapons or classes were added though. May or may not be worth the trade-off.