Strong Typing and Perl

(Strong Typing Doesn't Have to Suck)

Length: 90 minutes

Prerequisites: None.


I explain what typing is about, and why you might want it. I talk about the history of compile-time (static) type checking, and show some examples from FORTRAN (which does do it) and Lisp (which doesn't.) Then I show types in the ALGOL-derived languages, Pascal and C, and how they tried to extend static checking to aggregate types. I show that this has not worked well.

Since type checking in C and Pascal is a failure (and I have a big fit about this and foam at the mouth so that nobody dares disagree) there are two directions to go. You can give up on it, and many succesful langauges like Lisp, APL, Awk, and Perl do give up. This leads a lot of people to conclude that static type checking is a bad idea that has been abandoned.

But actually that's not so; it just shows that the inferior implementation in C and Pascal is a bad idea. Since C and Pascal were designed in the late 1960's, the state of the art has advanced, and languages like ML and Haskell have really good type systems.

I then spend about an hour showing examples of the ML type system. The big benefits here are: The type system is very fine-grained and flexible, so that there are many many types and you can be very specific about what type a certain value has. Types are deduced automatically by the compiler, so you don't need to declare them. Instead, you just write your code, and you look at the declarations that the compiler prints out and see if they were what you expected. If not, then your program almost certainly has a serious bug.

Finally, I talk about the possibility of adding good static type checking to Perl, and conclude that it's a lost cause because one of the essential features of Perl is that it automatically converts values from one type to another, which defeats the possibility of checking. I talk about the various hacks for run-time type checking in Perl, including strict 'refs' and the -w flag, and also some upcoming features for static type checking.

In addition to the slides, a complete writeup article is available.

Complete Slides

  1. Strong Typing
  2. On Holy Wars
  3. Why Types?
  4. Why Types?
  5. Early Type Systems: FORTRAN
  6. FORTRAN Continues
  7. Early Type Systems: Lisp
  8. Strong Typing in ALGOL-based languages
  9. Strong Typing: Hard to Get Right
  10. Strong Typing: Hard to Get Right
  11. Strong Typing in Pascal and C is a Failure
  12. Coping With Failure
  13. Strong Typing that Works
  14. The ML Programming Language
  15. Types in ML
  16. Types in ML
  17. Big Deal?
  18. Type Elaboration Example 2
  19. Type Elaboration Example 3: Union Types
  20. Union Type Sabotage
  21. Union Type Sabotage
  22. Final Note About Union Types
  23. Type Elaboration Example 4
  24. Type Elaboration Example 4 Continued
  25. Type Elaboration Example 5
  26. Life with ML
  27. A Spectacular Example
  28. Splitting
  29. Merge Sort
  30. Huh???
  31. Where's the Bug?
  32. Type Checking in Perl
  33. Type Checking in Perl: Gaaaack
  34. Run-Time Type Checking
  35. Compile-Time Type Checking
  36. Compile-Time Type Checking
  37. Compile-Time Type Checking
  38. Conclusion

Complete Writeup of Talk

Related Talks

Atypical Typing, a revised version of this talk, written for OOPSLA in 2008.

Return to: Universe of Discourse main page | Perl Paraphernalia | Other Classes and Talks