Generic Views on Data Types Problem Towards a solution Generic - - PowerPoint PPT Presentation

generic views on data types
SMART_READER_LITE
LIVE PREVIEW

Generic Views on Data Types Problem Towards a solution Generic - - PowerPoint PPT Presentation

Introduction Generic Views on Data Types Problem Towards a solution Generic Views Detour into GH The influence of S. Holdermans 1 J. Jeuring 1 oh 2 A. Rodriguez 1 A. L views Formal definition Validity Implementation 1 Department of


slide-1
SLIDE 1

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

1

Generic Views on Data Types

  • S. Holdermans1
  • J. Jeuring1
  • A. L¨
  • h2
  • A. Rodriguez1

1Department of Information and Computing Sciences, Utrecht University 2Institut f¨

ur Informatik III, Universit¨ at Bonn

8th International Conference on Mathematics of Program Construction - 2006

slide-2
SLIDE 2

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

2

Contents

Introduction Problem Towards a solution Generic Views Detour into GH The influence of views Formal definition Validity Implementation in Generic Haskell Generic Haskell Adding a view Conclusions

slide-3
SLIDE 3

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

3

So many approaches to generic programming. . .

Only in Haskell, we have:

◮ LIGD ◮ EMGM ◮ PolyP ◮ Regular ◮ and much more...

slide-4
SLIDE 4

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

3

So many approaches to generic programming. . .

Only in Haskell, we have:

◮ LIGD ◮ EMGM ◮ PolyP ◮ Regular ◮ and much more...

And they are NOT equivalent:

◮ Some generic functions are much easier to write in certain

frameworks then in others.

◮ Some just cannot be written in some frameworks. ◮ Performance can also vary greatly (time and space)...

slide-5
SLIDE 5

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

4

It’s not so chaotic, after all

What all approaches have in common

They all provide:

◮ A way to define generic functions by induction on the

structure of types

◮ Some view types, over which the functions are defined.

slide-6
SLIDE 6

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

4

It’s not so chaotic, after all

What all approaches have in common

They all provide:

◮ A way to define generic functions by induction on the

structure of types

◮ Some view types, over which the functions are defined.

Where they differ

Each approach views the structure of datatypes differently:

◮ Using a certain set of view types ◮ With certain conversions to and from these view types

slide-7
SLIDE 7

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

4

It’s not so chaotic, after all

What all approaches have in common

They all provide:

◮ A way to define generic functions by induction on the

structure of types

◮ Some view types, over which the functions are defined.

Where they differ

Each approach views the structure of datatypes differently:

◮ Using a certain set of view types ◮ With certain conversions to and from these view types

This paper

◮ Makes the case for generic views on datatypes ◮ Defines formally what is a generic view ◮ Shows an implementation of views (Generic Haskell)

slide-8
SLIDE 8

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

5

Why are generic views useful

◮ We will give examples of how the generic view used can

influence the expressiveness and efficiency of a generic programming approach

slide-9
SLIDE 9

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

5

Why are generic views useful

◮ We will give examples of how the generic view used can

influence the expressiveness and efficiency of a generic programming approach

◮ But first we need to have a minimal understanding of

Generic Haskell

slide-10
SLIDE 10

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

6

GH Basics

Generic Haskell

◮ Has a compiler which generates Haskell code ◮ Uses sum-of-products view types

slide-11
SLIDE 11

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

6

GH Basics

Generic Haskell

◮ Has a compiler which generates Haskell code ◮ Uses sum-of-products view types

Generic Haskell’s view types

1 data

Unit = Unit

2 data a + b = I n l

a | I n r b

3 data a × b = a × b

slide-12
SLIDE 12

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

7

GH Basics

A generic function in Generic Haskell

◮ Is type-indexed ◮ Just like in LIGD, slightly different syntax

slide-13
SLIDE 13

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

7

GH Basics

A generic function in Generic Haskell

◮ Is type-indexed ◮ Just like in LIGD, slightly different syntax

An example GH generic function

1 c o l l e c t <Unit>

Unit = [ ]

2 c o l l e c t <a+b> ( I n l

x ) = c o l l e c t <a> x

3 c o l l e c t <a+b> ( I n r

y ) = c o l l e c t <b> y

4 c o l l e c t <a × b> ( x × y ) = c o l l e c t <a> x ++ c o l l e c t <b> y 5 c o l l e c t <Int >

n = [ ]

6 c o l l e c t <Char>

c = [ ]

slide-14
SLIDE 14

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

7

GH Basics

A generic function in Generic Haskell

◮ Is type-indexed ◮ Just like in LIGD, slightly different syntax

An example GH generic function

1 c o l l e c t <Unit>

Unit = [ ]

2 c o l l e c t <a+b> ( I n l

x ) = c o l l e c t <a> x

3 c o l l e c t <a+b> ( I n r

y ) = c o l l e c t <b> y

4 c o l l e c t <a × b> ( x × y ) = c o l l e c t <a> x ++ c o l l e c t <b> y 5 c o l l e c t <Int >

n = [ ]

6 c o l l e c t <Char>

c = [ ]

Type signature

1 c o l l e c t <a : : ∗ | c ::∗ >

: : ( c o l l e c t <a | c>) ⇒ a → [ c ]

slide-15
SLIDE 15

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

8

Local re-definitions

Generic functions can be specialized using local re-definitions of the form:

1 l e t

c o l l e c t <a> x = i f x > 0 then [ x ] e l s e [ ]

2 i n

c o l l e c t <[a]>

slide-16
SLIDE 16

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

8

Local re-definitions

Generic functions can be specialized using local re-definitions of the form:

1 l e t

c o l l e c t <a> x = i f x > 0 then [ x ] e l s e [ ]

2 i n

c o l l e c t <[a]>

The expression above has type signature:

1 Num a ⇒ [ a ] → [ a ]

slide-17
SLIDE 17

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

9

Default cases

A specific function can be extended into a generic function by giving it a default case, like in the following example:

1 v a r c o l l e c t <Variable > v = [ v ] 2 v a r c o l l e c t

extends c o l l e c t

3

where c o l l e c t as v a r c o l l e c t

slide-18
SLIDE 18

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

9

Default cases

A specific function can be extended into a generic function by giving it a default case, like in the following example:

1 v a r c o l l e c t <Variable > v = [ v ] 2 v a r c o l l e c t

extends c o l l e c t

3

where c o l l e c t as v a r c o l l e c t

The where clause renames a dependency in the default case.

slide-19
SLIDE 19

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

10

GH final remarks

Structure types

GH uses sum-of-products, right-associative. Therefore a List representation type would look like:

1 data

L i s t a = N i l | Cons a ( L i s t a )

2 type

L ist ’ a = Unit + a × L i s t a

slide-20
SLIDE 20

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

10

GH final remarks

Structure types

GH uses sum-of-products, right-associative. Therefore a List representation type would look like:

1 data

L i s t a = N i l | Cons a ( L i s t a )

2 type

L ist ’ a = Unit + a × L i s t a

Lastly

Both the structure types themselves and the embedding projection pair are generated by the Generic Haskell compiler.

slide-21
SLIDE 21

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

11

Why generic views are useful

We will now show with some examples how the generic view can influence:

◮ The ease with which generic functions can be defined ◮ The performance of generic functions

The generic views discussed will be:

◮ Fixed points ◮ Balanced sums of products ◮ List-like sums of products

slide-22
SLIDE 22

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

12

Fixed points

Imagine defining a generic function to. . .

◮ Get the immediate recursive children of a value ◮ It is REALLY hard to define in Generic Haskell’s standard

view

◮ But not impossible. . .

slide-23
SLIDE 23

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

12

Fixed points

Imagine defining a generic function to. . .

◮ Get the immediate recursive children of a value ◮ It is REALLY hard to define in Generic Haskell’s standard

view

◮ But not impossible. . .

By ”manually” writing type-level fixed points

1 data

Fix f = In ( f ( Fix f ))

2 data TermBase

r

3

= VarBase V a r i a b l e

4

| AbsBase V a r i a b l e r | AppBase r r

5 type Term ’ = Fix

TermBase

6 data

TreeBase a b r = TipBase a | NodeBase r b r

7 type

Tree ’ a b = Fix ( TreeBase a b )

slide-24
SLIDE 24

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

13

Fixed points

A BIG disadvantage

◮ The user needs to redefine all recursive datatypes in terms

  • f Fix

◮ AND needs to provide conversion functions to and from

this ”Fix” view

slide-25
SLIDE 25

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

13

Fixed points

A BIG disadvantage

◮ The user needs to redefine all recursive datatypes in terms

  • f Fix

◮ AND needs to provide conversion functions to and from

this ”Fix” view

But this can be solved

◮ By using a fixed point view when writing this function. ◮ The compiler will generate the fixed points. Will also

generate and apply the mappings when necessary.

◮ The type signature of a function with this view would be: 1 c h i l d r e n <a : : ∗

viewed Fix>

2

: : ( f o r a l l c . c o l l e c t <a | c>) ⇒ a → [ a ]

slide-26
SLIDE 26

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

14

Balanced sums of products

◮ GH’s standard view is a right-deep sum-of-products ◮ This can be bad in some occasions. . .

slide-27
SLIDE 27

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

14

Balanced sums of products

◮ GH’s standard view is a right-deep sum-of-products ◮ This can be bad in some occasions. . .

For example

Consider a generic binary encoding function:

1 data

Bit = Off | On

2 enc<Unit> Unit = [ ] 3 enc<a + b> ( I n l

x ) = Off : enc<a> x

4 enc<a + b> ( I n r

y ) = On : enc<b> y

5 enc<a × b> ( x × y ) = enc<a> x ++ enc<b> y 6 enc<Int > n = e n c I n t

n

7 enc<Char> c = encChar

c

slide-28
SLIDE 28

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

15

Balanced sums of products

Then the following Compass type:

1 data Compass = North

| East | South | West

Has the following representation in GH’s standard view:

1 type CompassR = Unit + ( Unit + ( Unit + Unit ))

slide-29
SLIDE 29

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

15

Balanced sums of products

Then the following Compass type:

1 data Compass = North

| East | South | West

Has the following representation in GH’s standard view:

1 type CompassR = Unit + ( Unit + ( Unit + Unit ))

While the balanced representation looks like:

1 type CompassB = ( Unit + Unit ) + ( Unit + Unit ) ◮ CompassR uses at most 3 bits, CompassB at most 2 ◮ The generic view used influences the space efficiency

slide-30
SLIDE 30

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

16

List-like sums of products

Consider the problem of showing just a subtree of a value. We write a generic function showP for this task, along these lines:

slide-31
SLIDE 31

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

16

List-like sums of products

Consider the problem of showing just a subtree of a value. We write a generic function showP for this task, along these lines:

1 type

Path = [ I n t ]

2 showP<a ::∗ > 3

: : ( show ( a ) , showP<a>) ⇒ Path → a → S t r i n g

4 showP<a x b> ( 0 : p )

( x × y )

5

= i f n u l l p then show<a> x e l s e showP<a> p a

6 showP<a × b> ( n : p )

( x × y ) = showP<b> (( n −1):p ) b

7

. . .

slide-32
SLIDE 32

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

16

List-like sums of products

Consider the problem of showing just a subtree of a value. We write a generic function showP for this task, along these lines:

1 type

Path = [ I n t ]

2 showP<a ::∗ > 3

: : ( show ( a ) , showP<a>) ⇒ Path → a → S t r i n g

4 showP<a x b> ( 0 : p )

( x × y )

5

= i f n u l l p then show<a> x e l s e showP<a> p a

6 showP<a × b> ( n : p )

( x × y ) = showP<b> (( n −1):p ) b

7

. . .

This implementation attempt would not work with the following type, for example (lacking a product):

1 data Con012 a b = Con0

| Con1 a | Con2 a b

2 type

Con012 ’ a b = Unit + ( a + ( a × b ))

slide-33
SLIDE 33

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

17

List-like sums of products

To solve this, we can use a view in which there is always a sum and a product present. Then the previous representation becomes:

1 type

Con012 ’ ’ a b = Unit + (( a × Unit ) + (( a × ( b × Unit )) + Zero ))

slide-34
SLIDE 34

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

17

List-like sums of products

To solve this, we can use a view in which there is always a sum and a product present. Then the previous representation becomes:

1 type

Con012 ’ ’ a b = Unit + (( a × Unit ) + (( a × ( b × Unit )) + Zero ))

Then showP can be easily defined as:

1 showP<Unit>

Unit = e r r o r ” i l l e g a l path ”

2 showP<a × b> ( 0 : p )

( x × y ) = showP<a> p x

3 showP<a × b> ( n : p )

( x × y ) = showP<b> (( n −1):p ) b

4 showP<Zero>

= e r r o r ” cannot happen”

5 showP<a + b> [ ]

x = show<a + b> x

6 showP<a + b> p ( I n l

x ) = showP<a> p x

7 showP<a + b> p ( I n r

y ) = showP<b> p y

slide-35
SLIDE 35

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

18

Definition of a generic view

◮ In the paper a whole formal language is developed to

express generic views

◮ This language is based on the Core language

  • Extended with types, kinds, type declarations and

parameterized types

  • Also with type and kind environments
slide-36
SLIDE 36

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

18

Definition of a generic view

◮ In the paper a whole formal language is developed to

express generic views

◮ This language is based on the Core language

  • Extended with types, kinds, type declarations and

parameterized types

  • Also with type and kind environments

We have little time to expose all that formal language here. . .

slide-37
SLIDE 37

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

18

Definition of a generic view

◮ In the paper a whole formal language is developed to

express generic views

◮ This language is based on the Core language

  • Extended with types, kinds, type declarations and

parameterized types

  • Also with type and kind environments

We have little time to expose all that formal language here. . . However, a generic view is fundamentally:

slide-38
SLIDE 38

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

18

Definition of a generic view

◮ In the paper a whole formal language is developed to

express generic views

◮ This language is based on the Core language

  • Extended with types, kinds, type declarations and

parameterized types

  • Also with type and kind environments

We have little time to expose all that formal language here. . . However, a generic view is fundamentally:

◮ A set of view types

slide-39
SLIDE 39

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

18

Definition of a generic view

◮ In the paper a whole formal language is developed to

express generic views

◮ This language is based on the Core language

  • Extended with types, kinds, type declarations and

parameterized types

  • Also with type and kind environments

We have little time to expose all that formal language here. . . However, a generic view is fundamentally:

◮ A set of view types ◮ A mapping from each user type to one view type and some

supporting types

slide-40
SLIDE 40

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

18

Definition of a generic view

◮ In the paper a whole formal language is developed to

express generic views

◮ This language is based on the Core language

  • Extended with types, kinds, type declarations and

parameterized types

  • Also with type and kind environments

We have little time to expose all that formal language here. . . However, a generic view is fundamentally:

◮ A set of view types ◮ A mapping from each user type to one view type and some

supporting types

◮ A mapping from each user type to a pair of expressions

witnessing the isomorphism

slide-41
SLIDE 41

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

19

Validity of a generic view

A generic view is only valid if it satisfies three conditions:

slide-42
SLIDE 42

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

19

Validity of a generic view

A generic view is only valid if it satisfies three conditions:

◮ The mapping between user and view types is

kind-preserving

slide-43
SLIDE 43

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

19

Validity of a generic view

A generic view is only valid if it satisfies three conditions:

◮ The mapping between user and view types is

kind-preserving

◮ The conversion functions (to and from) are well-typed

slide-44
SLIDE 44

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

19

Validity of a generic view

A generic view is only valid if it satisfies three conditions:

◮ The mapping between user and view types is

kind-preserving

◮ The conversion functions (to and from) are well-typed ◮ The conversion functions are well-behaved

slide-45
SLIDE 45

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

19

Validity of a generic view

A generic view is only valid if it satisfies three conditions:

◮ The mapping between user and view types is

kind-preserving

◮ The conversion functions (to and from) are well-typed ◮ The conversion functions are well-behaved

  • to and from must be inverses of each other
slide-46
SLIDE 46

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

20

Generic views, implemented

◮ Functions in Generic Haskell can be defined for a particular

view

◮ All the views mentioned in the paper are implemented in

the current GH version

  • GH 1.80 (Emerald release - April 2008)
  • Homepage: http://www.cs.uu.nl/research/

projects/generic-haskell

slide-47
SLIDE 47

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

21

Adding a generic view to Generic Haskell

The authors have considered creating a language to describe new views to be added, but did not do it because:

slide-48
SLIDE 48

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

21

Adding a generic view to Generic Haskell

The authors have considered creating a language to describe new views to be added, but did not do it because:

◮ The existing views should be sufficient for most uses

slide-49
SLIDE 49

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

21

Adding a generic view to Generic Haskell

The authors have considered creating a language to describe new views to be added, but did not do it because:

◮ The existing views should be sufficient for most uses ◮ The view language would be TOO BIG

slide-50
SLIDE 50

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

21

Adding a generic view to Generic Haskell

The authors have considered creating a language to describe new views to be added, but did not do it because:

◮ The existing views should be sufficient for most uses ◮ The view language would be TOO BIG ◮ Modifying the GH compiler to add a new view is not so

hard as it might seem

slide-51
SLIDE 51

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

22

Adding a view to the GH compiler

A new generic view is added to the GH compiler by implementing a module that contains a top-level “view” declaration of type:

slide-52
SLIDE 52

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

22

Adding a view to the GH compiler

A new generic view is added to the GH compiler by implementing a module that contains a top-level “view” declaration of type:

1

(Name ,

2

TDecl→

3

Maybe (LamType , [ TDecl ] , Expr , Expr , [ TDecl ] ) )

slide-53
SLIDE 53

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

22

Adding a view to the GH compiler

A new generic view is added to the GH compiler by implementing a module that contains a top-level “view” declaration of type:

1

(Name ,

2

TDecl→

3

Maybe (LamType , [ TDecl ] , Expr , Expr , [ TDecl ] ) )

The GH compiler can automatically check that a view defined in this way:

◮ Is kind-preserving and well-typed ◮ But cannot proof that the embedding projection pair is

well-behaved (undecidable). This proof is still a burden on the human designer of the view

slide-54
SLIDE 54

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

23

Conclusions

◮ The view on datatypes chosen by a generic programming

library/language can strongly influence:

  • Expressiveness
  • Ease-of-use
  • Performance
slide-55
SLIDE 55

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

23

Conclusions

◮ The view on datatypes chosen by a generic programming

library/language can strongly influence:

  • Expressiveness
  • Ease-of-use
  • Performance

◮ Using multiple views in the same approach (Generic

Haskell) was original

  • Still is, according to my (limited) research. . .
slide-56
SLIDE 56

Introduction

Problem Towards a solution

Generic Views

Detour into GH The influence of views Formal definition Validity

Implementation in Generic Haskell

Generic Haskell Adding a view

Conclusions

24

Future work on the subject

More immediate

◮ Develop the view description language

”Blue skies research”

◮ Embed the possibility of using multiple views into a GP

library (and not a GP language).

◮ Make possible to add new views to a GP library with an

  • EDSL. . .