1

There is a programming "style" (or maybe paradigm, i'm not sure what to call it) which is as follows:

First, you write a specification: a formal description of what your (whole, or part of) program is to do. This is done within the programming system; it is not a separate artifact.

Then, you write the program, but - and this is the key distinction between this programming style and others - every step of this writing task is guided in some way by the specification you've written in the previous step. How exactly this guidance happens varies wildly; in Coq you have a metaprogramming language (Ltac) which lets you "refine" the specification while building the actual program behind the scenes, whereas in Agda you compose a program by filling "holes" (i'm not actually sure how it goes in Agda, as i'm mostly used to Coq).

This isn't exactly everyone's favorite style of programming, but i'd like to try practicing it in general-purpose, popular programming languages. At least in Coq i've found it to be fairly addictive!

...but how would i even search for ways to do it outside proof assistants? Which leads us to the question: I'm looking for a name for this programming style, so that i can try looking up tools that let me program like that in other programming languages.

Mind you, of course a more proper question would be directly asking for examples of such tools, but AFAIK questions asking for lists of answers aren't appropriate for Stack Exchange sites.

And to be clear, i'm not all that hopeful i'm really going to find much; these are mostly academic pastimes, and your typical programming language isn't really amenable to this style of programming (for example, the specification language might end up being impossibly complex). But it's worth a shot!

  • Some scattered thoughts: 1) Idris might be the most popular general-purpose programming language along these lines? 2) I know Frama-C has something to do with a specification language for C, maybe it is possible to program in this style within it? 3) Haskell has something called LiquidHaskell, is it an implementation of this style? – Hugo Carvalho de Paula Dec 24 '20 at 18:45
  • 1
    What you are describing seems to come close to a form of Refinement Calculus as can be found more or less explicitly in some papers about Coq (see for instance Intuitionistic Refinement Calculus by Sylvain Boulmé). That keyword seems to lead to many books and papers in software engineering in a broader sense... – kyo dralliam Dec 25 '20 at 22:13

3 Answers3

0

It is called proof-driven development (or type-driven development). However, there is very little information about it.

Hexirp
  • 410
  • 2
  • 11
0

This process you mention about slowly creating your program by means of ltac (in the case of coq) or holes (in the case of Agda and Idris) is called refinement. So you will also find reference in the literature for this style as proof by refinement or programming by refinement.

Now the most important thing to realize is that this style of programming is intrinsic to more complex type system that will allow you to extract as much information as possible the current environment. So it is natural to find attached with dependent types, although it is not necessarily the case.

As mentioned in another response you're also going to find references to it as Type-Driven Development, there is an idris book about it.

You may be interested in looking into some other projects such as Lean, Isabelle, Idris, Agda, Cedille, and maybe Liquid Haskell, TLA+ and SAW.

Pedro Abreu
  • 142
  • 5
0

As pointed out by the two previous answers, a possible name for the program style you mention certainly is: type-driven development.

From the Coq viewpoint, you might be interested in the following two references:

  • Certified Programming with Dependent Types (CPDT, by Adam Chlipala): a Coq textbook that teaches advanced techniques to develop dependently-typed Coq theories and automate related proofs.

  • Experience Report: Type-Driven Development of Certified Tree Algorithms in Coq (by Reynald Affeldt, Jacques Garrigue, Xuanrui Qi, Kazunari Tanaka), published at the Coq Workshop 2019 (slides, extended abstract):

    The authors also use the acronym TDD, which interestingly enough, also has another acceptation in the software engineering community: test-driven development (this widely used methodology naturally leads to high-quality test suites).
    Actually, both acceptations of TDD share a common idea: one systematically starts by writing the specification (of the considered unit), then only after that, writing some code that fulfills the spec (make the unit tests pass), then we loop and incrementally specify+implement(+refactor) other code units.

Last but not least, there are some extra pointers in this discussion from the Discourse OCaml forum.

ErikMD
  • 13,377
  • 3
  • 35
  • 71