Hostname: page-component-cd9895bd7-hc48f Total loading time: 0 Render date: 2024-12-21T06:44:28.139Z Has data issue: false hasContentIssue false

Sorted

Verifying the Problem of the Dutch National Flag in Agda

Published online by Cambridge University Press:  12 October 2011

WOUTER SWIERSTRA*
Affiliation:
Heijendaalseweg 135, 6525 AJ Nijmegen, the Netherlands (e-mail: w.swierstra@cs.ru.nl)
Rights & Permissions [Opens in a new window]

Extract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

The problem of the Dutch national flag was formulated by Dijkstra (1976) as follows:

There is a row of buckets numbered from 1 to n. It is given that:

  1. P1: each bucket contains one pebble

  2. P2: each pebble is either red, white, or blue.

A minicomputer is placed in front of this row of buckets and has to be programmed in such a way that it will rearrange (if necessary) the pebbles in the order of the Dutch national flag.

The minicomputer in question should perform this rearrangement using two commands:

  • swapi j for 1≤in and 1≤jn exchanges the pebbles stored in the buckets numbered i and j;

  • read (i) for 1≤in returns the colour of the pebble currently lying in bucket number i. Dijkstra originally named this operation buck.

Type
Functional Pearls
Copyright
Copyright © Cambridge University Press 2011

References

Bove, A. & Capretta, V. (2005) Modelling general recursion in type theory. Math. Struct. Comput. Sci. 15 (4), 671708.CrossRefGoogle Scholar
Bove, A. & Dybjer, P. (2009) Dependent types at work. In Language Engineering and Rigorous Software Development, Bove, A., Barbosa, L., Pardo, A. & Pinto, J. (eds), Lecture Notes in Computer Science, vol. 5520. Springer, pp. 5799.CrossRefGoogle Scholar
Brady, E. (2011) Idris-Systems programming meets full dependent types. In Proceedings of the 2011 ACM SIGPLAN Workshop on Programming Languages meets Programming Verification (PLPV '11).Google Scholar
Dijkstra, E. W. (1976) A Discipline of Programming. Prentice-Hall.Google Scholar
McBride, C. (2004) Epigram: Practical programming with dependent types. In Advanced Functional Programming. Vene, V. & Uustalu, T. (eds), LNCS-Tutorial, vol. 3622. Springer-Verlag, pp. 130170.Google Scholar
McBride, C. & McKinna, J. (2004) The view from the left. J. Funct. Program. 14 (1), 69111.CrossRefGoogle Scholar
Nordstrom, B., Petersson, K. & Smith, J. M. (1990) Programming in Martin-Löf's Type Theory: An Introduction. Oxford University Press.Google Scholar
Norell, U. (2007) Towards a Practical Programming Language Based on Dependent Type Theory. PhD. thesis. Chalmers University of Technology.Google Scholar
Norell, U. (2008) Dependently typed programming in Agda. In Advanced Functional Programming, Koopman, P., Plasmeijer, R., & Swierstra, D. (eds), LNCS-Tutorial, vol. 5832. Springer-Verlag, pp. 230266.Google Scholar
Oury, N. & Swierstra, W. (2008) The power of Pi. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP '08), pp. 39–50.CrossRefGoogle Scholar
PeytonJones, S. Jones, S. (ed) (2003) Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press.Google Scholar
Swierstra, W. (2008) A Functional Specification of Effects. PhD. thesis. University of Nottingham.Google Scholar
Supplementary material: File

Swierstra Supplementary Materials

Swierstra Supplementary Materials

Download Swierstra Supplementary Materials(File)
File 5 KB
Submit a response

Discussions

No Discussions have been published for this article.