Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Teaching haskell to juggle


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Teaching haskell to juggle

  1. 1. Teaching Haskell To Juggle Phil Freeman
  2. 2. Agenda• Theory• Finding valid patterns and their states• Why Haskell?• If there’s time: – Animating siteswaps with HOpenGL – Type level siteswaps
  3. 3. Siteswap Notation• Encodes timing of throws• Ignores hand positions• E.g. – 3-ball cascade ‘3,3,3,3,…’ – 3-ball shower ‘5,1,5,1,…’ – 4-ball fountain ‘4,4,4,4,…’
  4. 4. Siteswap Notation• Hands alternate – Even numbers indicate throws to the same hand – Odd numbers indicate throws to the other hand• Current ball will be thrown again after N-1 beats• Period = length (* 2)• Number of props = average value• 0 is a pause with an empty hand
  5. 5. Space Time Diagrams• Tracks the orbit of each balls between the hands• Axes represent – Time – Ball position• Time axis is divided into beats
  6. 6. Space Time Diagrams LH333 RH LH15 RH LH423 RH
  7. 7. State Diagrams• Tracks when balls in the air will land• An × indicates a ball scheduled to land• A - indicates a free hand• E.g. – 3-ball cascade: ×××-- – 3-ball shower: ×-×-× → ××-×- → ×-×-× – 4-ball fountain: ××××-
  8. 8. State Diagrams• To “throw” a 0, shift the pattern to the left: – -×××- →0 ×××--• To throw to height N, shift and insert an × at the Nth place: – ×××-- →5 ××--ו State diagrams and heights form the vertices and edges of a directed graph.• Valid siteswaps are cycles in this graph.
  9. 9. State Diagrams ×××-- ××-×- -×××- ×-××-E.g. 3 props, maximum height 4
  10. 10. Translation Siteswap Space Time State DiagramPeriod Length (* 2) Tiling Period Cycle Length (* 2)# of Props Average # of Orbits # of ×’sHeight Value Horizontal Max node label Distance length
  11. 11. Why Haskell?• Type safety• Side effects are isolated• Succinct – Pattern matching – Polymorphism – Higher order functions
  12. 12. Code Break• Finding Valid Siteswaps• throw, throwMany, foldM• graph, generateGraph• E.g. all patterns decorating a 3-cascade• E.g. over combinator
  13. 13. HOpenGL• Provides a high-level interface to the OpenGL bindings.• Computations take place in IO• E.g. preservingMatrix :: IO a -> IO a• Use powerful existing tools, e.g. mapM
  14. 14. Code Break• Animating Siteswaps• IORef• E.g. insert
  15. 15. Type Level Siteswaps• Idea: Can we use the type system to identify valid siteswaps?• E.g. Can we improve on the type of (++) for concatenating patterns?• Use singleton types, type classes and fundeps to encode the state graph in the type system.
  16. 16. Code Break• Type Level Siteswaps
  17. 17. Questions?