Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions typeclasses.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Playable a where
healingPower :: a -> Double

data Warrior =
Warrior
{ warriorName :: String
}

instance Playable Warrior where
healingPower _warrior = 1

data Mage =
Mage
{ mageName :: String
, wizardingPower :: Double
}

instance Playable Mage where
healingPower mage = wizardingPower mage * 0.5

chris = Warrior { warriorName = "Chris" }
julie = Mage { mageName = "Julie", wizardingPower = 9000 }

main = do
putStr "Julie's Healing Power: "
print $ healingPower julie

putStr "Chris' Healing Power: "
print $ healingPower chris