from the tagless final cookbook
play

From the Tagless-Final Cookbook Embedding and Optimizing (Hardware) - PowerPoint PPT Presentation

From the Tagless-Final Cookbook Embedding and Optimizing (Hardware) Domain-Specific Languages in the Typed Final Style http://okmij.org/ftp/tagless-final/course/index.html Metaprogramming Summer School 2019 Dagstuhl, August 13-15, 2019


  1. From the Tagless-Final Cookbook Embedding and Optimizing (Hardware) Domain-Specific Languages in the Typed Final Style http://okmij.org/ftp/tagless-final/course/index.html Metaprogramming Summer School 2019 Dagstuhl, August 13-15, 2019

  2. Tagless-Final A general method of embedding (often typed) domain-specific languages (DSL) in a typed functional language such as Haskell, OCaml, Scala and Coq ◮ An alternative to the (‘deep’) embedding as a (G)ADT ◮ Centered around interpreters ◮ Extensible ◮ Executable denotational semantics It has been used to implement extensible DSLs in the domains of language-integrated queries, non-deterministic and probabilistic programming, delimited continuations, computability theory, stream processing, hardware description languages, generation of specialized numerical kernels, and natural language semantics 2

  3. What’s new A variant, but not repetition of an earlier course (CUFP 2015, Metaprogramming Summer School 2016) The same DSL of combinational circuits but developed at a faster pace and to a larger extent Semantic rather than syntactic Focus on denotations rather than term rewriting 3

  4. Goals ◮ Introduce the Tagless-final style on a familiar example: combinational circuits ◮ Show off the features of the approach and design choice ◮ Introduce various optimizations Optimizing EDSL in the typed final style is not only possible: it is modular and systematic You can do it! 4

  5. Which language? OCaml, Haskell, Scala, ..., Coq, ... 5

  6. Overview Interactivity ◮ Please do ask questions ◮ I will ask questions ◮ Interactive writing of code (me vs. OCaml) ◮ Several exercises to do in class (and homework) ◮ Work alone or in group ◮ Installed OCaml? http://try.ocamlpro.com/ 6

  7. Problems ◮ A DSL for basic logical circuits (AND/OR/NOT) ◮ Various interpreters ◮ Compiler to NAND circuit ◮ Simplification and other transformers ◮ Conversion to CNF in one easy step ◮ From gates to circuits ◮ Circuit optimization, composionally ◮ Adding Gates (higher-order), reusing previous transformation rules Real-life application: efficient language-integrated query The web page of the approach (Tutorials, applications, etc.) http://okmij.org/ftp/tagless-final/course/index.html Similar, in spirit tutorial http://okmij.org/ftp/ tagless-final/course/optimizations.html 7

  8. Main ideas ◮ Multiple interpretations: write once, interpret many times ◮ Extensibility ◮ Types ◮ typed implementation language ◮ typed object language ◮ typed optimization rules ◮ connections with logic ◮ ‘Final’ ◮ everything is in lower-case ◮ prefer elimination over introduction ◮ connections to denotational semantics 8

  9. Main ideas ◮ Multiple interpretations: write once, interpret many times ◮ Extensibility ◮ Types ◮ typed implementation language ◮ typed object language ◮ typed optimization rules ◮ connections with logic ◮ Denotational ◮ seek meaning ◮ algebras ◮ evaluation rather than rewriting 8

  10. Compositionality The meaning of a complex expression is determined by its structure and the meanings of its constituents. http://plato.stanford.edu/entries/compositionality/ eval (Add e1 e2) = eval e1 + eval e2 ◮ Evaluators and other interpreters are compositional ◮ Denotational semantics must be compositional ◮ Compositionality is modularity ◮ Compositionality is context-insensitivity ◮ Bottom-up reconstruction of meaning ◮ Compositional processing is fold 9

  11. More problems, homework ◮ The problem noted in the source code files (search for QUIZ) ◮ Selective inlining (combine only those circuits when doing so will not lead to duplication) ◮ Sharing ◮ AND X X � X ◮ Implement various simplifications 10

  12. Why Tagless Final style? Thinking about meaning helps ◮ Algebraic perspective: focus on operations, on what we need to do (and how to add more: extensibility) ◮ Denotational perspective: focus on what we eventually want: eye on the prize rather than on word shuffling http://okmij.org/ftp/tagless-final/ http://okmij.org/ftp/tagless-final/cookbook.html http://okmij.org/ftp/tagless-final/Algebra.html http://okmij.org/ftp/tagless-final/semantics.html 11

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend