Advertisement

Typing Haskell with an Attribute Grammar

  • Atze Dijkstra
  • S. Doaitse Swierstra
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3622)

Abstract

A great deal has been written about type systems. Much less has been written about implementing them. Even less has been written about implementations of complete compilers in which all aspects come together. This paper fills this gap by describing the implementation of a series of compilers for a simplified variant of Haskell. By using an attribute grammar system, aspects of a compiler implementation can be described separately and added in a sequence of steps, thereby giving a series of increasingly complex (working) compilers. Also, the source text of both this paper and the executable compilers come from the same source files by an underlying minimal weaving system. Therefore, source and explanation is kept consistent.

Keywords

Type Variable Type Signature Abstract Syntax Semantic Function Typing Rule 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    The Glasgow Haskell Compiler (2004), http://www.haskell.org/ghc/
  2. 2.
    Abadi, M., Cardelli, L.: A Theory of Objects. Springer, Heidelberg (1996)zbMATHGoogle Scholar
  3. 3.
    Baars, A.: Attribute Grammar System. arSystem (2004), http://www.cs.uu.nl/groups/ST/twiki/bin/view/Center/AttributeGramm
  4. 4.
    Bird, R.S.: Using Circular Programs to Eliminate Multiple Traversals of Data. Acta Informatica 21, 239–250 (1984)zbMATHCrossRefGoogle Scholar
  5. 5.
    Boquist, U.: Code Optimisation Techniques for Lazy Functional Languages, PhD Thesis. Chalmers University of Technology (1999)Google Scholar
  6. 6.
    Boquist, U., Johnsson, T.: The GRIN Project: A Highly Optimising Back End For Lazy Functional Languages. In: Selected papers from the 8th International Workshop on Implementation of Functional Languages (1996)Google Scholar
  7. 7.
    Botlan, D., Le, Remy, D.: ML-F, Raising ML to the Power of System F. In: ICFP (2003)Google Scholar
  8. 8.
    Damas, L., Milner, R.: Principal type-schemes for functional programs. In: Proceedings of Principles of Programming Languages (POPL), pp. 207–212. ACM, New York (1982)Google Scholar
  9. 9.
    Damas, L., Milner, R.: Principal type-schemes for functional programs. In: 9th symposium Principles of Programming Languages, pp. 207–212. ACM Press, New York (1982)CrossRefGoogle Scholar
  10. 10.
    Diatchki, I.S., Jones, M.P., Hallgren, T.: A Formal Specification of the Haskell 98 Module System. In: Haskell Workshop, pp. 17–29 (2002)Google Scholar
  11. 11.
    Dijkstra, A.: EHC Web (2004), http://www.cs.uu.nl/groups/ST/Ehc/WebHome
  12. 12.
    Dijkstra, A., Swierstra, D.: Explicit implicit parameters. Technical Report UU-CS-2004-059, Institute of Information and Computing Science (2004)Google Scholar
  13. 13.
    Dijkstra, A., Swierstra, D.: Typing Haskell with an Attribute Grammar (Part I). Technical Report UU-CS-2004-037, Department of Computer Science, Utrecht University (2004)Google Scholar
  14. 14.
    Faxen, K.-F.: A Static Semantics for Haskell. Journal of Functional Programming 12(4), 295 (2002)zbMATHCrossRefMathSciNetGoogle Scholar
  15. 15.
    Gaster, B.R., Jones, M.P.: A Polymorphic Type System for Extensible Records and Variants. Technical Report NOTTCS-TR-96-3, Languages and Programming Group, Department of Computer Science, Nottingham (November 1996)Google Scholar
  16. 16.
    Hall, C., Hammond, K., Jones, S.P., Wadler, P.: Type Classes in Haskell. ACM TOPLAS 18(2), 109–138 (1996)CrossRefGoogle Scholar
  17. 17.
    Heeren, B., Hage, J., Swierstra, S.D.: Generalizing Hindley-Milner Type Inference Algorithms. Technical Report UU-CS-2002-031, Institute of Information and Computing Science, University Utrecht, Netherlands (2002)Google Scholar
  18. 18.
    Hindley, J.R.: The principal type-scheme of an object in combinatory logic. Transactions of the American Mathematical Society 146, 29–60 (1969)zbMATHMathSciNetGoogle Scholar
  19. 19.
    Johnsson, T.: Attribute grammars as a functional programming paradigm. In: Functional Programming Languages and Computer Architecture, pp. 154–173 (1987)Google Scholar
  20. 20.
    Jones, M.P.: Typing Haskell in Haskell. In: Haskell Workshop (1999)Google Scholar
  21. 21.
    Jones, M.P.: Typing Haskell in Haskell (2000), http://www.cse.ogi.edu/~mpj/thih/
  22. 22.
    Jones, M.P., Jones, S.P.: Lightweight Extensible Records for Haskell. In: Haskell Workshop, number UU-CS-1999-28. Utrecht University, Institute of Information and Computing Sciences (1999)Google Scholar
  23. 23.
    Kuiper, M.F., Swierstra, S.D.: Using Attribute Grammars to Derive Efficient Functional Programs. In: Computing Science in the Netherlands CSN 1987 (November 1987)Google Scholar
  24. 24.
    Lämmel, R., Jones, S.P.: Scrap your boilerplate: a practical design pattern for generic programming. In: Types In Languages Design And Implementation, pp. 26–37 (2003)Google Scholar
  25. 25.
    Laufer, K., Odersky, M.: Polymorphic Type Inference and Abstract Data Types. Technical Report LUC-001, Loyola University of Chicago (1994)Google Scholar
  26. 26.
    Milner, R.: A theory of type polymorphism in programming. Journal of Computer and System Sciences 17(3) (1978)Google Scholar
  27. 27.
    Mitchell, J.C., Plotkin, G.D.: Abstract Types Have Existential Type. ACM TOPLAS 10(3), 470–502 (1988)CrossRefGoogle Scholar
  28. 28.
    Odersky, M., Laufer, K.: Putting Type Annotations to Work. In: Principles of Programming Languages, pp. 54–67 (1996)Google Scholar
  29. 29.
    Odersky, M., Sulzmann, M., Wehr, M.: Type Inference with Constrained Types. In: Fourth International Workshop on Foundations of Object-Oriented Programming, FOOL 4 (1997)Google Scholar
  30. 30.
    Perry, N.: The Implementation of Practical Functional Programming Languages (1991)Google Scholar
  31. 31.
    Jones, S.P.: Haskell 98, Language and Libraries, The Revised Report. Cambridge Univ. Press (2003)Google Scholar
  32. 32.
    Jones, S.P., Shields, M.: Practical type inference for arbitrary-rank types (2004), http://research.microsoft.com/Users/simonpj/papers/putting/index.htm
  33. 33.
    Jones, S.P.: The Implementation of Functional Programming Languages. Prentice Hall, Englewood Cliffs (1987)zbMATHGoogle Scholar
  34. 34.
    Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)Google Scholar
  35. 35.
    Saraiva, J.: Purely Functional Implementation of Attribute Grammars. PhD thesis, Utrecht University (1999)Google Scholar
  36. 36.
    Shan, C.-c.: Sexy types in action. ACM SIGPLAN Notices 39(5), 15–22 (2004)CrossRefGoogle Scholar
  37. 37.
    Shields, M., Jones, S.P.: First-class Modules for Haskell. In: Ninth International Conference on Foundations of Object-Oriented Languages (FOOL 9), Portland, Oregon (December 2001)Google Scholar
  38. 38.
    Utrecht University Software Technology Group. UUST library (2004), http://cvs.cs.uu.nl/cgi-bin/cvsweb.cgi/uust/
  39. 39.
    Swierstra, S.D., Alocer, P.R.A., Saraiava, J.: Designing and Implementing Combinator Languages. In: Swierstra, D., Henriques, P., Oliveira, J. (eds.) Advanced Functional Programming, Third International School, AFP 1998. LNCS, vol. 1608, pp. 150–206. Springer, Heidelberg (1999)Google Scholar
  40. 40.
    Thompson, S.: Type Theory and Functional Programming. Addison-Wesley, Reading (1991)zbMATHGoogle Scholar
  41. 41.
    Wadler, P.: Theorems for free! In: 4’th International Conference on Functional Programming and Computer Architecture (September 1989)Google Scholar
  42. 42.
    Wadler, P.: Deforestation: transforming programs to eliminate trees. Theoretical Computer Science (Special issue of selected papers from 2’nd European Symposium on Programming) 73, 231–248 (1990)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2005

Authors and Affiliations

  • Atze Dijkstra
    • 1
  • S. Doaitse Swierstra
    • 1
  1. 1.Institute of Information and Computing SciencesUtrecht UniversityUtrechtNetherlands

Personalised recommendations