STAMP: Strongly Type-sAfe Meta-Programming Thomas Winant - - PowerPoint PPT Presentation

stamp strongly type safe meta programming
SMART_READER_LITE
LIVE PREVIEW

STAMP: Strongly Type-sAfe Meta-Programming Thomas Winant - - PowerPoint PPT Presentation

STAMP: Strongly Type-sAfe Meta-Programming Thomas Winant Dominique Devriese Jesper Cockx DistriNet KU Leuven 21 September 2015 Type-safe metaprogramming: Overview Most metaprogramming is weakly type-safe (e.g. Template Haskell)


slide-1
SLIDE 1

STAMP: Strongly Type-sAfe Meta-Programming

Thomas Winant Dominique Devriese Jesper Cockx

DistriNet – KU Leuven

21 September 2015

slide-2
SLIDE 2

Type-safe metaprogramming: Overview

Most metaprogramming is weakly type-safe (e.g. Template Haskell) generated programs may contain type errors type checker checks generated code With Agda as metalanguage, we can do better: embed Haskell type system in Agda generated code type correct by construction

1 / 10

slide-3
SLIDE 3

STAMP: Strongly Type-sAfe Meta-Programming

1 Why STAMP? 2 Examples 3 The STAMP architecture 4 The Agda encoding

slide-4
SLIDE 4

STAMP: Strongly Type-sAfe Meta-Programming

1 Why STAMP? 2 Examples 3 The STAMP architecture 4 The Agda encoding

slide-5
SLIDE 5

Why strongly type-safe metaprogramming?

we cannot test all possible pieces of code generated by a metaprogram type errors in generated code are impossible to debug by the user types document what can be expected of the metaprogram

2 / 10

slide-6
SLIDE 6

Why use Agda instead of a special-purpose metalanguage?

We can generate both the type and the typing context of the metaprogram together with the program itself

3 / 10

slide-7
SLIDE 7

STAMP: Strongly Type-sAfe Meta-Programming

1 Why STAMP? 2 Examples 3 The STAMP architecture 4 The Agda encoding

slide-8
SLIDE 8

Pick k’th from n function arguments

Given k and n, generate the following definition pick :: a1 -> ...

  • > an -> ak

pick x1 ... xn = xk

4 / 10

slide-9
SLIDE 9

Automatic deriving

Derive Eq Derive lenses

5 / 10

slide-10
SLIDE 10

STAMP: Strongly Type-sAfe Meta-Programming

1 Why STAMP? 2 Examples 3 The STAMP architecture 4 The Agda encoding

slide-11
SLIDE 11

The STAMP architecture

Added syntax to Haskell to make a STAMP call STAMP works as a Core2Core plugin call corresponding Agda metaprogram translate Agda representation to Haskell Core splice generated code into the right position

6 / 10

slide-12
SLIDE 12

Current shortcoming

calls to Haskell functions in generated code are not checked type error only after translation to core solution: need to generate Agda interface based on Haskell code

7 / 10

slide-13
SLIDE 13

STAMP: Strongly Type-sAfe Meta-Programming

1 Why STAMP? 2 Examples 3 The STAMP architecture 4 The Agda encoding

slide-14
SLIDE 14

The Agda encoding

Fairly standard encoding of System FC Kinds Types depend on kinds Terms depend on types

8 / 10

slide-15
SLIDE 15

Weakening and substitution

definition of Term datatype requires weakening and substitution of types we take TySubst Σ1 Σ2 = All (Type Σ2) Σ1

9 / 10

slide-16
SLIDE 16

Design based on Haskell documentation

good to verify correctness w.r.t. Haskell specification not very convenient for writing metaprograms (substitution hell) based on our experiences now, we hope to add a convenience layer later

10 / 10