10

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.

Community
  • 1
  • 1
ziggystar
  • 28,410
  • 9
  • 72
  • 124
  • Why is this tagged Haskell? These links may be of interest: http://blog.ezyang.com/2010/08/type-kata-controlled-sharing-of-references/ and http://blog.ezyang.com/2010/08/type-kata-newtypes/ – Edward Z. Yang Apr 06 '11 at 13:30
  • @Edward Because Scala's type system seems to be similar to Haskell's type system and maybe patterns for Haskell (which has been around for longer) transfer to Java. – ziggystar Apr 06 '11 at 14:06
  • @Edward I think this valid because the most adventurous experiments with Scala's type system seem to come from people with Haskell background, e.g. Rúnar's blog and the Scalaz people. – 0__ Apr 06 '11 at 14:16
  • 1
    It would be great to have something really extensive about this, maybe even a book. There are so many beginnner's books for Scala now, I think there is demand for an advanced book that deals exactly with this, design patterns for static type programming – 0__ Apr 06 '11 at 14:18

2 Answers2

6

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 :

You may also be interested in a related Oleg wondertrick : Lightweight static capabilities (with Chung-chieh Shan).

gasche
  • 31,259
  • 3
  • 78
  • 100
  • 1
    [phantom types in Scala](http://james-iry.blogspot.com/2010/10/phantom-types-in-haskell-and-scala.html) – ziggystar Apr 06 '11 at 14:55
2

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.

Community
  • 1
  • 1
Don Stewart
  • 137,316
  • 36
  • 365
  • 468