Algebraic Types are not Scary, Actually

65 points by aiono


dmbaturin

My favorite demonstration for beginners is a type that describes playing cards. It’s more familiar (for those who ever played card games, anyway) than ASTs, and you can show rank comparison, etc.

type suit = Diamonds | Hearts | Spades | Clubs

type card =
  Ace of suit
| King of suit
| Queen of suit
| Jack of suit
| Numeral of (suit * int)