ABSTRACT
Tools for computer languages need position information: compilers for providing better error messages, structure editors for mapping between structural and textual views, and debuggers for navigating through a term, for instance. Manually adding position information to an abstract syntax tree is tedious and requires pervasive changes: the original tree becomes verbose and every function operating on it needs to be adapted.
In this paper, we describe how to automatically extend datatypes with position information using datatype-generic programming techniques. Furthermore, we show examples of how to use this position information: parsers that automatically construct trees annotated with positions, catamorphisms that deal with failure by reporting error locations, and zippers that efficiently navigate annotated trees. The generic programming technique we describe is applicable to a wide range of domains.
Supplemental Material
- }}Gerard Huet. Functional pearl: The zipper. Journal of Functional Programming, 7(5):549--554, September 1997. Google ScholarDigital Library
- }}Oleg Kiselyov and Chung-chieh Shan. Annotating trees post factum. http://okmij.org/ftp/Algorithms.html#tree-annot, July 2008. {Code file TEvalNR.hs; Online; accessed 21-July-2010}.Google Scholar
- }}Jeroen Leeuwestein and Martijn van Steenbergen. GroteTrap. http:// www.haskell.org/haskellwiki/GroteTrap, June 2008. {Online; accessed 21-July-2010}.Google Scholar
- }}Daan Leijen and Erik Meijer. Parsec: Direct style monadic parser combinators for the real world. Technical Report UU-CS-2001-35, Department of Information and Computing Sciences, Utrecht University, 2001.Google Scholar
- }}Grant Malcolm. Data structures and program transformation. Science of Computer Programming, 14(2-3):255--279, 1990. Google ScholarDigital Library
- }}Conor McBride. The derivative of a regular type is its type of one-hole contexts (extended abstract), 2001. Unpublished manuscript, available via http://strictlypositive.org/diff.pdf.Google Scholar
- }}Conor McBride and Ross Paterson. Applicative programming with effects. Journal of Functional Programming, 18(1):1--13, 2008. Google ScholarDigital Library
- }}Thomas van Noort, Alexey Rodriguez Yakushev, Stefan Holdermans, Johan Jeuring, and Bastiaan Heeren. A lightweight approach to datatypegeneric rewriting. In Workshop on Generic Programming 2008, pages 13--24. ACM, 2008. Google ScholarDigital Library
- }}Simon Peyton Jones et al. Haskell 98, Language and Libraries. The Revised Report. Cambridge University Press, 2003. A special issue of Journal of Functional Programming.Google Scholar
- }}Alexey Rodriguez Yakushev, Stefan Holdermans, Andres Löh, and Johan Jeuring. Generic programming with fixed points for mutually recursive datatypes. In International Conference on Functional Programming 2009, pages 233--244. ACM, 2009. Google ScholarDigital Library
- }}Martijn M. Schrage. Proxima - a presentation-oriented editor for structured documents. PhD thesis, Utrecht University, The Netherlands, October 2004.Google Scholar
- }}Tom Schrijvers, Simon Peyton Jones, Manuel M. T. Chakravarty, and Martin Sulzmann. Type checking with open type functions. In International Conference on Functional Programming 2008, pages 51--62. ACM, 2008. Google ScholarDigital Library
- }}Martijn van Steenbergen. Generic selections of subexpressions. Master's thesis, Utrecht University, 2010.Google Scholar
- }}Wouter Swierstra. Data types à la carte. Journal of Functional Programming, 18(4):423--436, July 2008. Google ScholarDigital Library
- }}Sebastiaan Visser and Andres Löh. Generic storage in Haskell. In Workshop on Generic Programming 2010. ACM, 2010. To appear. Google ScholarDigital Library
Index Terms
- Generic selections of subexpressions
Recommendations
Layout-sensitive language extensibility with SugarHaskell
Haskell '12: Proceedings of the 2012 Haskell SymposiumProgrammers need convenient syntax to write elegant and concise programs. Consequently, the Haskell standard provides syntactic sugar for some scenarios (e.g., do notation for monadic code), authors of Haskell compilers provide syntactic sugar for more ...
Optimizing SYB traversals is easy!
The most widely used generic-programming system in the Haskell community, Scrap Your Boilerplate (SYB), also happens to be one of the slowest. Generic traversals in SYB are often an order of magnitude slower than equivalent handwritten, non-generic ...
The right kind of generic programming
WGP '12: Proceedings of the 8th ACM SIGPLAN workshop on Generic programmingHaskell is known for its strong, static type system. A good type system classifies values, constraining the valid terms of the language and preventing many common programming errors. The Glasgow Haskell Compiler (GHC) has further extended the type ...
Comments