archives

Real-life use case - which PLs support it nicely?

I am going to initiate a marginally on-topic discussion, Ehud - please correct me if it is not on-topic at all.

Let's say I have a well-defined binary file format1, consisting of structural elements of different granularity ranging from unsigned ints to tagged blocks to sequences to complete files, and I want to express this structural elements in my PL, covering at least reading the file, analyzing/transforming it at the level of structural elements (as opposed to bits/bytes), and writing it back. An example would be optimizing Flash file for size, while preserving its functionality.

Additional points for:

  1. Compile-time checking to some extent (yes, it's unfair)
  2. Natural support of tagged blocks - e.g., block with tag 22 must have this type, while block with tag 42 must have that type (explicit "switch" does not count)
  3. Natural support of bit-fields (explicit bit-shifting does not count)
  4. Ditto with variable bit-field length (Byte n; BitField[n] x; BitField[x] y)
  5. Symmetric serialization/deserialization specification (ideally this should be completely defined by the structure of type)
Well, I realize that this sound too much like a DSL for describing file formats, but the question is - which of general-purpose PLs come sufficiently close to this (very informal) specification? Is dependent typing the most natural solution for variable length of fields and tagged blocks?
1If you are familiar with SWF you may think of this hypothetical format as SWF (if not, think RIFF, MIDI, etc.).