07 An ADT for Pokémon

Pokémon fight each other, and they have types:

And some others, but we'll ignore than for now

Depending on their type, they do more or less damage. Let's write some OCaml code to model Pokémon.

We can't have them both be called Normal, because they would shadow each other, so we're calling one ENormal and one TNormal for Effectiveness and Type

In OCaml, it's idiomatic to write mult_of_eff rather than mult_to_eff.

Next, let's encode the table of effectiveness of attacks

We could also rewrite this function to use or patterns:

Now let's calculate the effectiveness of some pairs

You might also want to write it as a function that takes each argument separately

This is a topic called Currying. You can read more in the textbook.

Now let's implement a type for an actual pokémon!

Now we have Charmander modeled as an actual pokémon!