# Functional programming with sets

## Abstract

Set abstraction, originally introduced in fuctional languages by Turner, is an appealing construct because it leads to concise definitions of many interesting operations. However, existing approaches treat sets as lists for the sake of efficiency, and thereby sacrifice a simple declarative semantics. In this paper, we present a novel language based on sets and equations, where sets are treated as sets, consistent with their semantics. The language is called SEL, for Set-Equation Language. Equations are assumed to define a confluent rewriting system when oriented left to right. Sets are defined in terms of their subsets; these rules define a nonconfluent rewriting system when oriented left to right. We show examples of programs in this language, and provide an operational semantics for such programs. Programs are executed by innermost reduction, which may be nondeterministic or deterministic. Nondeterministic reduction is used when one of the elements of a set is desired. Deterministic reduction is used to simplify a term via an equation or to obtain all the elements of a set. The correctness of the operational semantics is also established.

## Keywords

Normal Form Logic Program Operational Semantic Functional Programming Functional Language## References

- [B83]A. Bundy, “The Computer Modelling of Mathematical Reasoning,” Academic Press, New York, 1983.Google Scholar
- [BD85]L. Bachmair and N. Dershowitz, “Commutation, transformation, and temination,” In
*Proc. of 8th Int'l CADE*, Oxford, Springer Lecture Notes in Computer Science,**230**, pp. 5–20.Google Scholar - [BKN85]D. Benanav, D. Kapur, and P. Narendran, “On the complexity of matching problems,” In
*Rewriting Techniques and Applications*, pp. 417–429, Dijon, France, May 1985.Google Scholar - [BP85]L. Bachmair and D.A. Plaisted, “Associative Path Ordering,”
*J. of Symbolic Computation*,**1**, pp. 329–349.Google Scholar - [C78]K. L. Clark, “Negation as Failure,” In
*Logic and Data Bases*, Ed. H. Gallaire and J. Minker, Plenum Press, New York, 1978, pp. 293–322.Google Scholar - [CK81]J. S. Conery and D. F. Kibler, “Parallel Interpretation of Logic Programs,” In
*Conf. Functional Prog. Lang. and Comp. Arch., ACM*, 1981, pp. 163–170.Google Scholar - [CM81]W. F. Clocksin and C. S. Mellish,
*Programming in Prolog*. Springer-Verlag, New York, 1981.Google Scholar - [D82]N. Dershowitz, “Orderings for term-rewriting systems,”
*Theoretical Computer Science*,**17**, pp. 279–301.Google Scholar - [D85]N. Dershowitz, “Termination of Rewriting,” Technical report UIUCDCS-R-85-1220, University of Illinois at Urbana-Champaign, August 1985.Google Scholar
- [DP85]N. Dershowitz and D. A. Plaisted, “Applicative Programming
*cum*Logic Programming,” In*1985 Symp. on Logic Programming*, Boston, pp. 54–66.Google Scholar - [DFP86]J. Darlington, A.J. Field, and H. Pull, “Unification of Functional and Logic Languages,” In DeGroot and Lindstrom (eds.),
*Logic Programming, Relations, Functions and Equations*, pp. 37–70, Prentice-Hall, 1986.Google Scholar - [FW80]D.P. Friedman and D.S. Wise, “An Indeterminate Constructor for Applicative Programming,” In
*7th ACM POPL*, pp. 245–250, Las Vegas, January 1980.Google Scholar - [H80]G. Huet, “Confluent Reductions: abstract properties and applications to term rewriting systems,”
*J. ACM*,**27**, 1980, pp. 797–821.Google Scholar - [HO80]G. Huet and D. Oppen, “Equations and Rewrite Rules: a Survey,” In
*Formal Languages: Perspectives and Open Problems*, R. Book (ed.), Academic Press, New York 1980.Google Scholar - [HO82]C. M. Hoffman and M. J. O'Donnell, “Programming with Equations,”
*ACM TOPLAS***4**, No. 1 (January 1982) pp. 83–112.Google Scholar - [JS86]B. Jayaraman and F.S.K. Silbermann, “Equations, Sets, and Reduction Semantics for Functional and Logic Programming,”
*In 1986 ACM Symposium on LISP and Functional Programming*, pp. 320–331, Boston, 1986.Google Scholar - [KB70]D. E. Knuth and P. Bendix, “Simple Word Problems in Universal Algebras,” In
*Computational Problems in Abstract Algebra*, J. Leech (ed.), Pergamon Press, New York, pp. 263–297, 1970.Google Scholar - [K82]R. M. Keller, “FEL (Function Equation Language) Programmer's Guide,” AMPS Technical Memo 7, Department of Computer Science, University of Utah, April 1982.Google Scholar
- [N85]L. Naish, “All Solutions Predicates in Prolog,” In
*Symp. on Logic Programming*, Boston, 1985, pp. 73–77.Google Scholar - [O85]M. J. O'Donnell, “Equational logic as a programming language,” M.I.T. Press, 1985.Google Scholar
- [P85]D.A. Plaisted, “Semantic Confluence Tests and Completion Methods,”
*Information and Control*,**65**, pp. 182–215, 1985.Google Scholar - [P86]D.A. Plaisted, “Nondeterminism by Associative-Commutative Rewriting,” Internal Report, Department of Computer Science, University of North Carolina, Chapel Hill, March 1986, 30 pages.Google Scholar
- [R84]J. A. Robinson, “New Generation Knowledge Processing: Syracuse University Parallel Expression Reduction,” First Annual Progress Report, December 1984.Google Scholar
- [R85]U. S. Reddy, “Narrowing as the Operational Semantics of Functional Languages,” In
*1985 Symp. on Logic Programming*, Boston, 1985, pp. 138–151.Google Scholar - [T81]D. A. Turner, “The semantic elegance of applicative languages,” In
*ACM Symp. on Func. Prog. and Comp. Arch.*, New Hampshire, October, 1981, pp. 85–92.Google Scholar