Darcs and GADTs

49
Darcs and GADTs Ganesh Sittampalam Credit Suisse

description

Darcs and GADTs. Ganesh Sittampalam Credit Suisse. Outline. Darcs GADTs How GADTs help darcs. Version control systems. Keep a history of changes to a project A basis for collaboration Lock based Merge based. Centralised VCS. CVS Subversion (SVN) Clearcase …. Distributed VCS. Arch - PowerPoint PPT Presentation

Transcript of Darcs and GADTs

Page 1: Darcs and GADTs

Darcs and GADTs

Ganesh SittampalamCredit Suisse

Page 2: Darcs and GADTs

Outline

• Darcs

• GADTs

• How GADTs help darcs

Page 3: Darcs and GADTs

Version control systems

• Keep a history of changes to a project

• A basis for collaboration– Lock based– Merge based

Page 4: Darcs and GADTs

Centralised VCS

CVS

Subversion (SVN)

Clearcase

Page 5: Darcs and GADTs

Distributed VCS

ArchMercurialBzr

GitDarcs…

Page 6: Darcs and GADTs

Tree-based merging

A B

result?

Page 7: Darcs and GADTs

Tree-based merging

A B

• Find basebase

result?

Page 8: Darcs and GADTs

Tree-based merging

A B

• Find base

• Calculate diffs

• Adjust offsets

• Apply

base

result

Page 9: Darcs and GADTs

Tree-based merging

A B

• Find base

• Calculate diffs

• Adjust offsets

• Apply

base

result

Page 10: Darcs and GADTs

Tree-based merging

• Base can be hard to find– Can have to artificially construct it

• Ignores the intermediate revisions– Not compositional

• Can choose algorithm at time of merge

Page 11: Darcs and GADTs

Patch-based merging

• Each revision is viewed as a “patch” against the previous version

• Merge algorithm is locked in when patch is created– “Intelligent” patch types like token replace

• Sequences of revisions merged by merging individual patches– Results repeatable and compositional

Page 12: Darcs and GADTs

Darcs

• Repo is conceptually a set of patches

• Representation places them in an order– Only some orders are valid

• Push and pull patches between repos

• Branches are just repos with different sets of patches– Merge = take the union

Page 13: Darcs and GADTs

Commutation

A

BB’

A’

AB B’A’

Makes cherry-picking easy

Page 14: Darcs and GADTs

Merging

A

B’ ?B

A’ ?

Page 15: Darcs and GADTs

Merging

A

B’ ?B

A’ ?

A

B’ ?

B

A’ ?

Page 16: Darcs and GADTs

Merging

A

B’ ?B

A’ ?

A

B’-1 ?

B-1

A’ ?

Page 17: Darcs and GADTs

Patch theory

• Set of rules about how patches behave

• Not yet properly understood– Very few theorems

• Notation a bit confusing

Page 18: Darcs and GADTs

Some basic properties

AB B’A’

B’A’ AB

B’-1A A’B-1

Page 19: Darcs and GADTs

“Permutivity”

A

BB’

A’

CC’

A’’

C’’

B’’

A’’’

B’’’

C’’’

Page 20: Darcs and GADTs

“Permutivity”

A

BB’

A’

CC’

A’’

C’’

B’’

A’’’

B’’’

C’’’

ABC

Page 21: Darcs and GADTs

“Permutivity”

A

BB’

A’

CC’

A’’ ABC

B’A’C

C’’

B’’

A’’’

B’’’

C’’’

Page 22: Darcs and GADTs

“Permutivity”

A

BB’

A’

CC’

A’’ ABC

B’A’C

B’C’A’’

C’’

B’’

A’’’

B’’’

C’’’

Page 23: Darcs and GADTs

“Permutivity”

A

BB’

A’

CC’

A’’ ABC

B’A’C

B’C’A’’

C’’B’’A’’

C’’

B’’

A’’’

B’’’

C’’’

Page 24: Darcs and GADTs

“Permutivity”

A

BB’

A’

CC’

A’’ ABC

B’A’C

B’C’A’’

C’’B’’A’’

C’’A’’’B’’’C’’

B’’

A’’’

B’’’

C’’’

Page 25: Darcs and GADTs

“Permutivity”

A

BB’

A’

CC’

A’’ ABC

B’A’C

B’C’A’’

C’’B’’A’’

C’’A’’’B’’’

A’’’’C’’’B’’’C’’

B’’

A’’’

B’’’

C’’’

Page 26: Darcs and GADTs

“Permutivity”

A

BB’

A’

CC’

A’’ ABC

B’A’C

B’C’A’’

C’’B’’A’’

C’’A’’’B’’’

A’’’’C’’’B’’’

A’’’’B’’’’C’’’’

C’’

B’’

A’’’

B’’’

C’’’

Page 27: Darcs and GADTs

Some GHC extensions

Page 28: Darcs and GADTs

ADT

data Expr t = Const t| Times (Expr t) (Expr t)

Times (Const ‘a’) (Const ‘b’) ??

Algebraic = unrestricted sums and products

Page 29: Darcs and GADTs

ADT

data Expr t where Const :: t Expr t Times :: Expr t Expr t Expr t

with new syntax

Times (Const ‘a’) (Const ‘b’) ??

Algebraic = unrestricted sums and products

Page 30: Darcs and GADTs

GADTs

data Expr t where Const :: t Expr t Times :: Expr Int Expr Int Expr Int

Times (Const ‘a’) (Const ‘b’)

Generalised algebraic = restricted sums and products

Page 31: Darcs and GADTs

“Existential” types

data Number = forall x . Num x Number x

Number (5 :: Int)Number (5.0 :: Double)…

We can construct Number using any x in Num

Page 32: Darcs and GADTs

“Existential” types

data Number = forall x . Num x Number x

inc :: Number Numberinc (Number a) = Number (a+1)

instance Show Number where show (Number a) = show a

When we use Number, we only know that x is in Num

Show x Num x

Page 33: Darcs and GADTs

Existential types, GADT style

data Number = forall x . Num x Number x

data Number where Number :: Num x x Number

Page 34: Darcs and GADTs

Putting these types to work

Page 35: Darcs and GADTs

data Patch where Null :: Patch Seq :: Patch Patch Patch …

Working with patches

AB B’A’

commute :: Patch Patch Maybe (Patch, Patch)

Page 36: Darcs and GADTs

Working with patches

commute :: Patch Patch Maybe (Patch, Patch)

commute (Seq a b) c= do (a’, c’) commute a c

(b’, c’’) commute b c’return (Seq a’ b’, c’’)

(AB)C ?

Page 37: Darcs and GADTs

Working with patches

commute :: Patch Patch Maybe (Patch, Patch)

commute (Seq a b) c= do (b’, c’) commute b c

(a’, c’’) commute a c’return (Seq a’ b’, c’’)

(AB)C ?

Page 38: Darcs and GADTs

GADT

data Patch x y where Null :: Patch x x Seq :: Patch x y Patch y z Patch x z …

commute :: Patch x y Patch y z Maybe (Patch x w, Patch w z)

Phantom types represent the repository state

Page 39: Darcs and GADTs

What’s going on?

A

BB’

A’

AB B’A’ commute :: Patch x y Patch y z Maybe(Patch x w, Patch w z)

x y

zw

Page 40: Darcs and GADTs

Safer commute

A

C’C’’

A’

B

B’

C

x y

zw

t

u

commute :: Patch x y Patch y z Maybe (Patch x w, Patch w z)

Page 41: Darcs and GADTs

So is it actually useful?

• Upcoming darcs 2.0 release– Rewrite of conflict handling code– Conditionally compiled with GADTs– Very positive influence:

• Conversion process found at least one bug in existing code

• “very valuable in exploratory development”

Page 42: Darcs and GADTs

Limitations

• There have to be “unsafe” operations in some places– e.g. when constructing “primitive” patches– Cordon those off to a small number of cases, and

use comments to explain ourselves

• Working with GADTs can be painful– Extra type signatures– Confusing error messages

Page 43: Darcs and GADTs

The end

Page 44: Darcs and GADTs

Sealing

commute :: Patch x y Patch y z Maybe (Patch x w, Patch w z)

Page 45: Darcs and GADTs

Sealing

commute :: forall x y w z . Patch x y Patch y z Maybe (Patch x w, Patch w z)

Page 46: Darcs and GADTs

Sealing

commute :: forall x y w z . Patch x y Patch y z Maybe (Patch x w, Patch w z)

data CommutePair x y where CommutePair :: Patch x y Patch y z

Patch x z

Page 47: Darcs and GADTs

Sealing

commute :: forall x z . CommutePair x z Maybe (CommutePair x z)

data CommutePair x y where CommutePair :: Patch x y Patch y z

Patch x z

Page 48: Darcs and GADTs

Data structures

data FL p x y where NilFL :: FL p x x ConsFL :: FL p x y FL p y z FL p x z

data Tree p x where NilTree :: Tree x SeqTree :: p x y Tree y Tree x ParTree :: Tree x Tree x Tree x

Page 49: Darcs and GADTs

DAGs

• Based on Martin Erwig’s inductive graphs