The Functional Programming Language XSLT - A proof through examplesSummaryNot only the purpose of this article to prove that XSLT can be considered a functional programming language has been fulfilled by providing XSLT implementation for the most major FP design patterns and examples from John Hughes article "Why Functional Programming matters" (this article contains the code of 35 functions), but as a side effect we have now available what can be considered the first XSLT functional programming library. The full library code, together with test examples demonstrating the use of individual functions, is available at the downloads page of TopXML.COM as specified in the links at the start of this article. The fxsl library and its next versions are (will be) available also as part of the evaluation version of the Xselerator IDE, which can be downloaded at http://www.topxml.com/xselerator/ . This is done with the purpose to assure that the new fxsl library releases would be made constantly available to the thousands of highly experienced XSLT programmers, who are users of Xselerator. Anyone, who is interested to study and start using the fxsl library, can do this now. DiscussionWe have provided a multitude of examples illustrating the usefulness of higher-order functions in XSLT. Most of the examples from John Hughes article "Why Functional Programming matters" have been implemented and the XSLT code demonstrated. Many of them (e.g. foldl, foldr, foldl-tree, map, buildListWhile, buildListWhileMap) are important functional programming design patterns that can generate unlimited types of new functions, depending on the functions passed to them as parameters. All this is more than an ample proof that XSLT is in fact a full-pledged functional programming language. On the other side, the XSLT code of those functions seems too-verbose compared to the corresponding Haskell code. The process of writing functional XSLT code can be made much more straightforward and easier by providing support for higher-order functions in XPath and XSLT, thus definitely improving even further the compactness, readability and reliability of XSLT functional code. It is the ideal time right now for the W3C XPath 2.0 working group to make the decision to provide the necessary support for higher-order functions as part of the standard XPath 2.0 specification. In case this golden opportunity is missed, then generic templates and libraries will be used in the years to come. Resources[1]Why Functional Programming Matters By John Hughes A brilliant paper, explaining the essence and beauty of the most important FP concepts. Multiple, very nice examples. Beautiful and elegant -- this is a "must read" for everyone who needs to understand what FP is all about. [2] Functional Programming and XML By Bijan Parsia: Describes support for XML in some FP languages: HaXML, LambdaXML and Erlang. [3] What kind of language is XSLT? By Michael Kay:("Note: Although XSLT is based on functional programming ideas, it is not as yet a full functional programming language, as it lacks the ability to treat functions as a first-class data type.") [4] A formal semantics of patterns in XSLT (PDF) By Philip Wadler A researcher with major contributions in the area of formal definition of the semantics of XSLT and XPath The home page of the FP language Haskell. [7] Haskell, The Craft of Functional Programming, Second Edition By Simon Thompson [8] XSL Transformations (XSLT) Version 1.0W3C Recommendation 16 November 1999 [9] Personal communication with Corey Haines, through messages in the xsltalk forum. [10] A Gentle Introduction to Haskell, Version 98 By Paul Hudak, John Peterson, Joseph Fasel About the authorDimitre Novatchev is the author of the popular tool for learning XPath -- the XPath Visualizer, and he developed the first systematic implementation of the concept of "generic templates". His background (and PhD, a long time ago) is in computer science and mathematics. He has been working at Fujitsu Australia on various aspects of OODBMS, including XML support for Jasmine. At the time of writing Dimitre is a software development manager at the UN Centre in Vienna, Austria.
|