Lingua Franca of Functional Programming (FP)
Scheme is a minimalist language that brings its ancestor, LISP, on par with modern languages such as *ML and Haskell. Although it has very different tools in its repertoire (e.g., homoiconicity), many of the same techniques applied in other languages are also quite usable in Scheme. Some of them (e.g., pattern-matching, monadic and multi-stage programming, a notation for laziness) tend to be associated with other languages (primarily: Haskell and OCaml), and hence many programmers liking these constructs are drawn away from Scheme.
The concrete reason for this in FP community is the perceived verbosity of Scheme, while others (in particular, from the embedded community) have troubles adopting the more difficult concepts of FP in general. It is clear that there are approaches developed with FP that do help for productivity in hardware and software design. Transfer of this knowledge, however, is made difficult by an intellectual gap between the communities. In this paper we attempt to reconcile these two points of view by showing that (1) Scheme’s minimalistic but flexible approach can bring concrete benefits to the embedded community, and (2) none of these “advanced” features is particularly hard to replicate in a language such as Scheme. If one is willing to leverage Scheme’s hygienic macros, all of these features can be implemented separately as libraries and freely used together. No advanced compiler or interpreter modifications to implement such extensions are required for creating embedded DSLs in it.
To really see what Scheme (and homoiconicity) can bring to the domain of automated program construction, and to apply these ideas in practice to Software-Defined Radio (SDR) stacks, we have re-implemented a multi-staged, monadic FFT generator. In this paper we supplement it with a straightforward implementation of the C code-generation and Graphviz visualization back-ends and argue for a homoiconic, pure and total language to combine the best features of Scheme, Haskell and *ML.
Unable to display preview. Download preview PDF.
- 1.Adams IV, N.I., Bartley, D.H., Brooks, G., Dybvig, R.K., Friedman, D.P., Halstead, R., Hanson, C., Haynes, C.T., Kohlbecker, E., Oxley, D., Pitman, K.M., Rozas, G.J., Steele Jr., G.L., Sussman, G.J., Wand, M., Abelson, H.: Revised5 report on the algorithmic language scheme. SIGPLAN Not. 33(9), 26–76 (1998)CrossRefGoogle Scholar
- 2.Alexandrescu, A.: Better template error messages. C/C++ Users J. 17(3), 37–47 (1999)Google Scholar
- 3.Bender, J.: sxml-match.ss. InternetGoogle Scholar
- 4.Calypto. Catapult c. InternetGoogle Scholar
- 8.Filinski, A.: Representing monads. In: POPL, pp. 446–457 (1994)Google Scholar
- 9.Foltzer, A.C., Friedman, D.P.: A schemers view of monads. Partial draft (2011)Google Scholar
- 10.Forte, D.S.: Cynthesizer. InternetGoogle Scholar
- 11.Friedman, D., Hilsdale, E., Ganz, S., Dybvig, K.: match.ss. InternetGoogle Scholar
- 13.Kiselyov, O.: Monadic programming in scheme. Internet (2005)Google Scholar
- 14.Kiselyov, O., Swadi, K.N., Taha, W.: A methodology for generating verified combinatorial circuits. In: Proceedings of the 4th ACM International Conference on Embedded Software, EMSOFT 2004, pp. 249–258. ACM, New York (2004)Google Scholar
- 17.Meijer, E., Hutton, G.: Bananas in space: Extending fold and unfold to exponential types. In: FPCA, pp. 324–333 (1995)Google Scholar
- 20.Queinnec, C., Geffroy, P.: Partial evaluation applied to symbolic pattern matching with intelligent backtrack. In: WSA, pp. 109–117 (1992)Google Scholar
- 21.Rompf, T., Odersky, M.: Lightweight modular staging: a pragmatic approach to runtime code generation and compiled dsls. In: Visser, E., Järvi, J. (eds.) GPCE, pp. 127–136. ACM (2010)Google Scholar
- 23.Shinn, A.: match.scm. InternetGoogle Scholar
- 24.Siskind, J.M.: Flow-directed lightweight closure conversion. Technical Report 99-190R, NEC Research Institute, Inc. (1999)Google Scholar
- 25.Stroustrup, B.: The c++0x “remove concepts” decision. InternetGoogle Scholar
- 27.Swadi, K.N., Taha, W., Kiselyov, O., Pasalic, E.: A monadic approach for avoiding code duplication when staging memoized functions. In: Hatcliff, J., Tip, F. (eds.) PEPM, pp. 160–169. ACM (2006)Google Scholar
- 28.Tobin-Hochstadt, S.: Extensible pattern matching in an extensible language. CoRR, abs/1106.2578 (2011)Google Scholar
- 29.Tobin-Hochstadt, S., St-Amour, V., Culpepper, R., Flatt, M., Felleisen, M.: Languages as libraries. In: Hall, M.W., Padua, D.A. (eds.) PLDI, pp. 132–141. ACM (2011)Google Scholar
- 31.Wright, A.K., Duba, B.F.: Pattern matching for scheme. Technical Report TX 77251-1892, Rice University (May 1995)Google Scholar
- 32.Yallop, J.: Ocaml patterns extesions. InternetGoogle Scholar