Ordinarily, a compiler for a multi-level language will contain some knowledge of the object language; for example, in a multi-stage programming language with runtime code generation, the compiler will know how to produce code which emits machine code for object language expressions. This means that adding, extending, or replacing the object language requires knowledge of compiler internals.

Generalized arrows act as an intermediate language, separating the meta language compiler from the object language implementation. Two-level expressions are flattened [11] into ordinary one-level expressions polymorphic in an instance of the GArrow class, which is used to represent object language expressions. Operations on object language expressions are then packaged in an instance of the GArrow class, which is a library rather than part of the compiler.

This paper presents an example application of this approach: a bit-serial circuit which searches for SHA-256 hash collisions. A two-level circuit-building program is passed through the GHC flattening pass (which is not specific to hardware design in any way) and the resulting one-level program is combined with a GArrow instance that emits Verilog code; this instance is an ordinary Haskell library which can be written without knowledge of compiler internals.


Object Language Hardware Design Functional Language Recursive Structure Code Type 
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.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Backus, J.: Can programming be liberated from the von neumann style? a functional style and its algebra of programs. Communications of the ACM 21(8), 613–641 (1978), MathSciNetzbMATHCrossRefGoogle Scholar
  2. 2.
    Bjesse, P., Claessen, K., Sheeran, M., Singh, S.: Lava: hardware design in haskell. In: ICFP 1998 (January 1998),
  3. 3.
    Claessen, K., Sands, D.: Observable Sharing for Functional Circuit Description. In: Thiagarajan, P.S., Yap, R.H.C. (eds.) ASIAN 1999. LNCS, vol. 1742, pp. 62–73. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  4. 4.
    Erkök, L., Launchbury, J.: Recursive monadic bindings. In: Proceedings of ICFP 2000, pp. 174–185. ACM (2000),
  5. 5.
    Gill, A.: Type-safe observable sharing in haskell. In: Haskell Symposium, pp. 117–128. ACM (2009),
  6. 6.
    Gill, A., Bull, T., Kimmell, G., Perrins, E., Komp, E., Werling, B.: Introducing Kansas Lava. In: Morazán, M.T., Scholz, S.-B. (eds.) IFL 2009. LNCS, vol. 6041, pp. 18–35. Springer, Heidelberg (2010), CrossRefGoogle Scholar
  7. 7.
    Grundy, J., Melham, T., O’leary, J.: A reflective functional language for hardware design and theorem proving. Journal of Functional Programming 16(2), 157–196 (2005), MathSciNetzbMATHCrossRefGoogle Scholar
  8. 8.
    Hasegawa, M.: Decomposing Typed Lambda Calculus into a Couple of Categorical Programming Languages. In: Johnstone, P.T., Rydeheard, D.E., Pitt, D.H. (eds.) CTCS 1995. LNCS, vol. 953, pp. 200–219. Springer, Heidelberg (1995), CrossRefGoogle Scholar
  9. 9.
    Hughes, J.: The Design of a Pretty-Printing Library. In: Jeuring, J., Meijer, E. (eds.) AFP 1995. LNCS, vol. 925, pp. 53–96. Springer, Heidelberg (1995), CrossRefGoogle Scholar
  10. 10.
    Matthews, J., Cook, B., Launchbury, J.: Microprocessor specification in hawk. In: Proceedings of 1998 International Conference on Computer Languages, pp. 90–101 (May 1998)Google Scholar
  11. 11.
    Megacz, A.: Multi-Level Languages are Generalized Arrows. CoRR, abs/1007.2885 (2010),, DBLP,
  12. 12.
    Milner, R.: Calculi for interaction. Acta Inf. 33(8), 707–737 (1996), MathSciNetCrossRefGoogle Scholar
  13. 13.
    Nielson, F., Neilson, H.R.: Two-Level Functional Languages. Cambridge University Press, Cambridge (1992)zbMATHCrossRefGoogle Scholar
  14. 14.
    Pfenning, F., Lee, P.: Metacircularity in the polymorphic λ-calculus. Theoretical Computer Science 89(1), 137–159 (1991), MathSciNetzbMATHCrossRefGoogle Scholar
  15. 15.
    Pfenning, F., Paulin-Mohring, C.: Inductively Defined Types in the Calculus of Constructions. In: Schmidt, D.A., Main, M.G., Melton, A.C., Mislove, M.W. (eds.) MFPS 1989. LNCS, vol. 442, pp. 209–228. Springer, Heidelberg (1990), CrossRefGoogle Scholar
  16. 16.
    Selinger, P.: A survey of graphical languages for monoidal categories (August 23, 2009),
  17. 17.
    Sheard, T., Linger, N.: Programming in omega. Tech. rep., 2nd Central European Functional Programming School (2007)Google Scholar
  18. 18.
    Sheeran, M.: muFP, A language for VLSI design. In: LISP and Functional Programming, pp. 104–112 (1984)Google Scholar
  19. 19.
    Taha, W., Sheard, T.: Multi-stage programming with explicit annotations. SIGPLAN Not. 32(12), 203–207 (1997) ISSN: 0362-1340, doi: 10.1145/258994.259019,
  20. 20.
    Taha, W., Nielsen, M.F.: Environment classifiers, pp. 26–37 (2003),

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Adam Megacz
    • 1
  1. 1.Computer Science DivisionUC BerkeleyUSA

Personalised recommendations