23
Type-safe Evolution of Spreadsheets acome Cunha Joost Visser Tiago Alves Jo˜ ao Saraiva Universidade do Minho, Portugal, {jacome,jas}@di.uminho.pt Software Improvement Group, The Netherlands, {j.visser,t.alves}@sig.eu FASE (ETAPS) 2011 March 26 – 3 April acome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 1 / 23

Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Type-safe Evolution of Spreadsheets

Jacome Cunha Joost Visser Tiago Alves Joao Saraiva

Universidade do Minho, Portugal, {jacome,jas}@di.uminho.ptSoftware Improvement Group, The Netherlands, {j.visser,t.alves}@sig.eu

FASE (ETAPS) 2011

March 26 – 3 April

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 1 / 23

Page 2: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Agenda

1 Motivation

2 An Example Scenario

3 Modeling Spreadsheets

4 Two-Level Transformation (2LT)

5 Modeling Spreadsheets, Again

6 Evolution RulesCombinator RulesSemantic RulesLayout Rules

7 Conclusions

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 2 / 23

Page 3: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Motivation

Spreadsheets are widely used;

Spreadsheets are notoriously error-prone;

Many errors are introduced when changing data;

But many others when changing the structure;

Models capturing the interdependencies between data can help;

Co-evolution of models and instances.

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 3 / 23

Page 4: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

An Example

Budget for travel, hotel and local transportation expenses.

At the beginning of each year, it needs to be modified toaccommodate the next year;

Several steps are necessary:add three new rows, labels, update formulas, etc.

Very prone to errors.

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 4 / 23

Page 5: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

An Example - Changing the Model

For expenses before and after tax, additional columns need to beinserted in the block of each year.

The user needs to change all the year in the spreadsheet.

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 5 / 23

Page 6: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

ClassSheets: Specifying Spreadsheets

Erwig and Engels have introduced ClassSheets to specifyspreadsheets;

ClassSheets allow to express business object structures within aspreadsheet using concepts from the OO paradigm;

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 6 / 23

Page 7: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Modeling our Example

Class to represent a year;

Class to represent budget line;

Class to represent the relationship between them.

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 7 / 23

Page 8: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Co-evolution of Model and Instances

We have a model to specify spreadsheets: ClassSheets;

And we have the instances: spreadsheet data;

We need to synchronize them;

We use data refinements.

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 8 / 23

Page 9: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Two-Level Transformation (2LT)

A

to&&

6 A′

from

ff

A, A′ data type and transformed data typeto witness function of type A→ A′

(injective and entire relation)from witness function of type A′ → A

(surjective, possibly partial)from ◦ to = idA

Implementation of data refinements theory;

Two-level rewiring system;

Transforming a type into another also produces data migrationfunctions;

We can compose refinements.

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 9 / 23

Page 10: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

2LT Rules - An Example

Maps from natural numbers to some type, N ⇀ A, are the implementationof lists of that type, A?:

A?

seq2index**

6 N ⇀ A

list

hh

seq2index creates a map where the keys are the indexes of theelements of the list;

list collects the elements in the map.

seq2index [’a’, ’z’, ’x’] = {1 7→ ’a’, 2 7→ ’z’, 3 7→ ’x’}list {1 7→ ’a’, 2 7→ ’z’, 3 7→ ’x’, 4 7→ ’k’} = [’a’, ’z’, ’x’, ’k’]

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 10 / 23

Page 11: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Spreadsheet Models in 2LT

2LT designed to algebraic data type;

We have created a representation for spreadsheet models based onClassSheets;

Reused the 2LT framework: when specifying a model transformation,we get for free functions to migrate data back and forward.

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 11 / 23

Page 12: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Spreadsheet Models in 2LT - References

References pose a particular challenge;

We implemented them as a pair of selection functions: one selects thecell which is the reference and another select the referenced cell.

s

A

to&&

target ..

source00

T +3 A′

from

ff

source′nn

target′ppt

source Projection over type Aidentifying the reference

target Projection over type Aidentifying the referenced cell

source ′ = source ◦ fromtarget ′ = target ◦ from

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 12 / 23

Page 13: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Evolution Rules

Combinators: defined as helper rules

Semantic: rules that add information to the model

Layout: rules that do not add information to the model, just changeits arrangement

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 13 / 23

Page 14: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Combinators - Pull up all the references

All references must be at the top level;

For example,

A× Bφ becomes (A× B)φ

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 14 / 23

Page 15: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Combinators - Apply after and friends

Applies another rules after something (e.g., a label, a block)

For example,

after "Cost" (addColumn "New Column" 0)

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 15 / 23

Page 16: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Semantics - Insert a column

A column is a composed by a label "l" and a default value v :

insertCol "l" v

The references are projection function;

We can not reference the exiting spreadsheet;

The formula is inserted as undefined and is correctly set after:

(once (insertCol "After Tax" FRef )) B(setFormula auxType fromRef toRef )

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 16 / 23

Page 17: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Semantics - Make it expandable

Allows some part to be added more columns/rows;

An example:

b becomes b→ or b↓

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 17 / 23

Page 18: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Semantics - Split

Moves a column to a new location;

The old value columns are substituted by references to the newposition;

Similar to create a pointer;

The new column does not contain repeated values.

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 18 / 23

Page 19: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Layout - Change orientation

It changes the entire spreadsheet orientation from vertical tohorizontal;

And vice versa.

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 19 / 23

Page 20: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Layout - Normalize blocks

Some results are not well formated:

A common example is to have as result the following type:

A p B ˆC p DˆE p F

Most of the times, the correct result is the following:

A p B p DˆE p C p F

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 20 / 23

Page 21: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Layout - Shift

Shift vertically or horizontally;

It moves the required part of the spreadsheet in the desired direction;

It leaves the old place empty.

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 21 / 23

Page 22: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Make It Expandable (in Haskell)

It is possible to make a block expandable:

(label : clas)

id×head--

6 (label : (clas)↓)

id×tolistll

Its implementation is as follows:

expandBlock :: String → RuleexpandBlock str (label : clas) | compLabel label str = do

let rep = Rep {to = id × tolist, from = id × head }return (View rep (label : (clas)↓))

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 22 / 23

Page 23: Type-safe Evolution of Spreadsheetsalfa.di.uminho.pt/~jacome/down/fase11_talk.pdf · Type-safe Evolution of Spreadsheets J acome Cunha Joost Visser Tiago Alves Jo~ao Saraiva Universidade

Conclusions

We have created a safe representation of spreadsheet models (andinstances);

Our techniques handle references and formulas;

We have shown rules for coupled evolution of models and instances;

We wish to make this available for spreadsheet users;

Thus, we are working on an embedding of our techniques inOpenOffice.org (submitted paper).

Jacome Cunha (UMinho-SIG) Type-safe Evolution of Spreadsheets FASE (ETAPS) 2011 23 / 23