Per Vognsen suggests a Haskell version of the damage function from my Schematic Tables talk:
data Attack = Magic | Melee
hit surprise defense attack = damage
where effectiveness = power * (if surprise then 3 else 2)
(power, damage) = case attack of
Magic -> (5, max 0 (effectiveness - defense))
Melee -> (4, 2 * effectiveness / defense)
This passes pairs of values (power, damage) through conditionals. That allows the conditionals to multiplex more than one value, rather than being repeated. I suspect I could stymie that approach with more complex data flows, but I am happy to acknowledge that Haskell does OK on this example. Thanks, Per.
