nus-cs3281 / 2017

A repo to hold info on CS3281 students
2 stars 1 forks source link

Phantom types #49

Open Neurrone opened 7 years ago

Neurrone commented 7 years ago

Outline:

Slides

Neurrone commented 7 years ago

PUMA outline:

  1. Audience: fellow CS3281/2 students
  2. Objective: To encourage use of phantom types
  3. Topic: Prevent bugs at compile-time with phantom types
  4. PUNCH: Show real scenario that could have been prevented using phantom types
  5. WIIFY: Learn a technique that you can immediately use to write code with less bugs.
  6. Promise:
    • WHAT are phantom types?
    • Why are phantom types worth using?
    • When to/not to use phantom types?
  7. Content:
    • WHAT are phantom types?
      • Explained through an example
      • Key point: phantom types is a technique that cleverly uses type parameters to augment types with extra info
    • WHY use phantom types?
      • Encode invariants into the type system so we can use the compiler to find bugs
      • Easy
      • No runtime costs
      • Support: demonstrate with examples
      • Key point: Using phantom types is worth doing because it lets you catch some bugs at compile-time
    • When to/not to use?
  8. Key points / summary statement / elevator pitch
    • Phantom types is a technique where unused type parameters in types can be used to augment the type with extra info.
    • Distinguish types that are otherwise identical at compile-time, e.g if the type has multiple states - sanitized vs unsanitized, units of measurement
    • Use only when pros > cons (like design patterns)
    • Easy and worth doing,
  9. Call to action: Let’s start using phantom types!

Do: start using phantom types Believe: using phantom types is easy and worthwhile Know: what are phantom types, why and when they are useful