1 / 49

Darcs and GADTs

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

tareq
Download Presentation

Darcs and GADTs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Darcs and GADTs Ganesh SittampalamCredit Suisse

  2. Outline • Darcs • GADTs • How GADTs help darcs

  3. Version control systems • Keep a history of changes to a project • A basis for collaboration • Lock based • Merge based

  4. Centralised VCS CVS Subversion (SVN) Clearcase …

  5. Distributed VCS Arch Mercurial Bzr Git Darcs …

  6. Tree-based merging A B result?

  7. Tree-based merging • Find base base A B result?

  8. Tree-based merging • Find base • Calculate diffs • Adjust offsets • Apply base A B result

  9. Tree-based merging • Find base • Calculate diffs • Adjust offsets • Apply base A B result

  10. 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

  11. 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

  12. 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

  13. AB B’A’ A’ B’ B A Commutation Makes cherry-picking easy

  14. A’ ? B B’ ? A Merging

  15. A’ ? B B’ ? A Merging B’ ? A’ ? A B

  16. A’ ? B B’ ? A Merging B’-1? A’ ? A B-1

  17. Patch theory • Set of rules about how patches behave • Not yet properly understood • Very few theorems • Notation a bit confusing

  18. AB B’A’ B’A’ AB B’-1A A’B-1 Some basic properties  

  19. “Permutivity” A’’ C’ C B’’ B’’’ A’ A’’’ B’ C’’ B C’’’ A

  20. “Permutivity” A’’ ABC C’ C B’’ B’’’ A’ A’’’ B’ C’’ B C’’’ A

  21. “Permutivity” A’’ ABC B’A’C C’ C B’’ B’’’ A’ A’’’ B’ C’’ B C’’’ A

  22. “Permutivity” A’’ ABC B’A’C C’ C B’’ B’C’A’’ B’’’ A’ A’’’ B’ C’’ B C’’’ A

  23. “Permutivity” A’’ ABC B’A’C C’ C B’’ B’C’A’’ B’’’ A’ C’’B’’A’’ A’’’ B’ C’’ B C’’’ A

  24. “Permutivity” A’’ ABC B’A’C C’ C B’’ B’C’A’’ B’’’ A’ C’’B’’A’’ A’’’ C’’A’’’B’’’ B’ C’’ B C’’’ A

  25. “Permutivity” A’’ ABC B’A’C C’ C B’’ B’C’A’’ B’’’ A’ C’’B’’A’’ A’’’ C’’A’’’B’’’ B’ C’’ B A’’’’C’’’B’’’ C’’’ A

  26. “Permutivity” A’’ ABC B’A’C C’ C B’’ B’C’A’’ B’’’ A’ C’’B’’A’’ A’’’ C’’A’’’B’’’ B’ C’’ B A’’’’C’’’B’’’ C’’’ A’’’’B’’’’C’’’’ A

  27. Some GHC extensions

  28. ADT data Expr t = Const t| Times (Expr t) (Expr t) Times (Const ‘a’) (Const ‘b’) ?? Algebraic = unrestrictedsums and products

  29. ADT with new syntax data Expr t where Const :: t  Expr t Times :: Expr t  Expr t  Expr t Times (Const ‘a’) (Const ‘b’) ?? Algebraic = unrestrictedsums and products

  30. 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

  31. “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

  32. “Existential” types data Number = forall x . Num x  Number x inc :: Number  Number inc (Number a) = Number (a+1) instance Show Number where show (Number a) = show a Show x  Num x When we use Number, we only know that x is in Num

  33. Existential types, GADT style data Number = forall x . Num x  Number x  data Number where Number :: Num x  x  Number

  34. Putting these types to work

  35. AB B’A’ Working with patches data Patch where Null :: Patch Seq :: Patch  Patch  Patch … commute :: Patch  Patch  Maybe (Patch, Patch)

  36. (AB)C ? 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’’)

  37. (AB)C ? 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’’)

  38. 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

  39. AB B’A’ A’ B’ B A What’s going on? commute :: Patch x y Patch y z Maybe(Patch x w, Patch w z) w z x y

  40. Safer commute commute :: Patch x y Patch y z Maybe (Patch x w, Patch w z) A’ B’ w u z C’’ C’ C x t y A B

  41. 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”

  42. 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

  43. The end

  44. Sealing commute :: Patch x y  Patch y z  Maybe (Patch x w, Patch w z)

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

  46. 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

  47. 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

  48. 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

  49. DAGs • Based on Martin Erwig’s inductive graphs

More Related