Design patterns for static type checking

I'm currently trying to figure out which aspects of my program can be statically type checked by the scala compiler. After reading this question I came up with the idea of design patterns for types. I find it pretty complicated to get my head around what might be possible with Scala's type system. So I'd like to look at practical usages (not peano arithmetic or stuff like that). Simple patterns that reappear often in normal code.

Does anyone know of any blogs or even books that deal with this question? Preferably in Scala, but it might also be useful for other languages.


I think one of the most useful things that would deserve the name "design pattern" is the "phantom types" technique. It is a more-or-less-systematic way to encode static information in a type parameter. See some examples :

  • Haskell wiki
  • an OCaml blog
  • a Haskell blog
  • You may also be interested in a related Oleg wondertrick : Lightweight static capabilities (with Chung-chieh Shan).


    You might look at the design advice for Haskell, and specifically, some of the more recent research papers on embedding strong properties into the type system:

  • Putting Curry-Howard to Work Tim Sheard, Proceedings of the 2005 ACM SIGPLAN workshop on Haskell. Tallinn, Estonia, 74 - 85, 2005
  • Language-Based Program Verification via Expressive Types Martin Sulzmann and Razvan Voicu. In Programming Languages meet Program Verification (PLPV'06)
  • Typed Contracts for Functional Programming Ralf Hinze, Johan Jeuring and Andres Loh.
  • A Library for Light-weight Information-Flow Security in Haskell A Russo, K Claessen, J Hughes .
  • There's no standard methodologies here yet, though there are many many nice examples of individual problems.

    链接地址: http://www.djcxy.com/p/42874.html

    上一篇: 在Haskell中设计和使用数据类型的最佳实践

    下一篇: 静态类型检查的设计模式