functional programming is everywhere
play

Functional Programming is Everywhere Ilya Sergey ilyasergey.net - PowerPoint PPT Presentation

Functional Programming is Everywhere Ilya Sergey ilyasergey.net PLMW @ ICFP 2019 2 About myself MSc Saint Petersburg State University, 2008 PhD KU Leuven, 2008-2012 Currently Associate Professor (tenure-track) at Yale-NUS College


  1. Functional Programming is Everywhere Ilya Sergey ilyasergey.net PLMW @ ICFP 2019

  2. 
 
 2 About myself MSc Saint Petersburg State University, 2008 
 PhD KU Leuven, 2008-2012 Currently Associate Professor (tenure-track) at Yale-NUS College & NUS 
 Previously Lecturer → Associate Professor at University College London 
 Postdoc at IMDEA Software Institute 
 Software Engineer at JetBrains

  3. 3 Functional programmer since 2005

  4. 4 Functional programmer since 2005 2005 2006 2007 2008 2010 2011

  5. 5 Functional Languages

  6. 6 The Essence of Functional Languages • Higher-order functions and closures • Algebraic Data Types • Types and Type Inference • Pattern Matching • Polymorphism • Folds • Laziness • Continuations and CPS • Point-free style • Structural Recursion • Combinator Libraries • Type Classes • Purely functional data structures • Monads Check out this year’s ICFP program…

  7. 7 This Talk Functional Programming

  8. 8 This Talk Functional Programming

  9. 9 This Talk Functional Programming Ideas λ

  10. 10 Functional Programming Ideas in… Teaching Software Engineering Research Disclaimer : personal experience

  11. 11 Functional Programming Ideas in… Teaching Software Engineering Research

  12. 12 Moore’s Law Transistor count still rising Clock speed flattening sharply

  13. 13 The Multicore Processor Sun All on the cache cache cache T2000 same chip Bus Bus Niagara shared memory

  14. 14

  15. 15 Specifications for Concurrent Data Structures

  16. 16 My research agenda since 2014 Reusable Specifications for Concurrent Data Structures

  17. Abstract Specifications of a Stack { S = xs } { S ′ = x :: xs } push x { S = xs } { res = ⊥ ⋀ S = Nil pop() ⋁ ∃ x, xs ′ . res = x ⋀ 
 xs = x :: xs ′ ⋀ S ′ = xs ′ } Suitable for sequential programming

  18. Abstract Specifications of a Stack { S = xs } { S ′ = x :: xs } push x { S = xs } { res = ⊥ ⋀ S = Nil pop() ⋁ ∃ x, xs ′ . res = x ⋀ 
 xs = x :: xs ′ ⋀ S ′ = xs ′ } Breaks composition in the presence of thread interference.

  19. { S = Nil } y := pop(); { y = ??? }

  20. { S = Nil } � � � � push 1; � � y := pop(); � � � � push 2; � � { y ∈ { ⊥ } ∪ {1, 2} } � � � �

  21. N o p r (not thread-modular) o o f { S = Nil } r e u s e � � � � � � � � push 1; � � � � y := pop(); push 3; � � � � � � � � push 2; � � � � { y ∈ { ⊥ } ∪ {1, 2, 3} } � � � � � � � �

  22. A reusable specification for pop? { S = Nil } y := pop(); { y = ??? }

  23. 23 The Essence of Functional Languages • Higher-order functions and closures • Algebraic Data Types • Types and Type Inference • Pattern Matching • Polymorphism • Folds • Laziness • Continuations and CPS • Point-free style • Structural Recursion • Combinator Libraries • Type Classes • Purely functional data structures • Monads

  24. 24 The Essence of Functional Languages • Higher-order functions and closures • Algebraic Data Types • Types and Type Inference • Pattern Matching • Polymorphism • Folds • Laziness • Continuations and CPS • Point-free style • Structural Recursion Enablers for Modular Development • Combinator Libraries • Type Classes • Purely functional data structures • Monads

  25. Idea: Interference- Parameterised Specifications Capture the e ff ect of self-thread , 
 parametrise over the e ff ect of others . (aka Subjective specifications )

  26. Atomic stack specifications { S ′ = x :: xs } { S = xs } push x

  27. Atomic stack specifications xs x :: xs t k → “abstract timestamp”

  28. } t k → t k+1 → t k+2 → t k+3 → abstract time increases at 
 {z t k+4 → every concrete push/pop operation …… t k+n → |

  29. Changes by this thread Changes by other threads t k → t k+1 → t k+2 → t k+3 → t k+4 → …… t k+n →

  30. Subjective stack specifications Sergey, Nanevski, Banerjee [ESOP’15] • H s — “ghost history” of my pushes/pops to the stack • H o — “ghost history” of pushes/pops by all other threads { H s = ∅ } λ H o . pick ( pushed (H o )) y := pop(); { y = ⊥ ⋁ y = v , where v ∈ pushed (H o ) } | {z } what I popped depends 
 on what the others have pushed

  31. { S = Nil } � � � � � � � � push 1; � � � � y := pop(); push 3; � � � � � � � � push 2; � � � � � � � � � � � �

  32. { H s = ∅ } push 1; { H s = t 1 ↦ (xs, 1 ::xs) } push 2; { H s = t 1 ↦ (xs, 1 ::xs) ⊕ t 2 ↦ (ys, 2 ::ys) }

  33. { H s = ∅ } push 1; { H s = t 1 ↦ (xs, 1 ::xs) } push 2; { H s = t 1 ↦ (xs, 1 ::xs) ⊕ t 2 ↦ (ys, 2 ::ys) }

  34. { H s = ∅ } � � push 1; { H s = ∅ } � � � � { H s = t 1 ↦ (xs, 1 ::xs) } push 3; � � � � � � push 2; { H s = t 3 ↦ (zs, 3 ::zs) } � � � � { H s = t 1 ↦ (xs, 1 ::xs) ⊕ t 2 ↦ (ys, 2 ::ys) }

  35. { H s = ∅ } � � � � { H s = ∅ } { H s = ∅ } � � � � push 1; � � � � y := pop(); push 3; � � � � � � � � push 2; � � � � { H s = t 3 ↦ (zs, 3 ::zs) } { y ∈ { ⊥ } ∪ pushed (H o ) } � � � � { H s = t 1 ↦ (xs, 1 ::xs) ⊕ 
 � � � � t 2 ↦ (ys, 2 ::ys) }

  36. { H s = ∅ } � � � � { H s = ∅ } { H s = ∅ } � � � � push 1; � � � � y := pop(); push 3; � � � � � � � � push 2; � � � � { H s = t 3 ↦ (zs, 3 ::zs) } 3 { y ∈ { ⊥ } ∪ pushed (H o ) } � � � � { H s = t 1 ↦ (xs, 1 ::xs) ⊕ 
 1 � � � � t 2 ↦ (ys, 2 ::ys) } 2

  37. { H s = ∅ } � � � � { H s = ∅ } { H s = ∅ } � � � � push 1; � � � � y := pop(); push 3; � � � � � � � � push 2; � � � � { H s = t 3 ↦ (zs, 3 ::zs) } { y ∈ { ⊥ } ∪ { 1 , 2 , 3 } } � � � � { H s = t 1 ↦ (xs, 1 ::xs) ⊕ 
 � � � � t 2 ↦ (ys, 2 ::ys) }

  38. Payo ff : Verified Concurrent Libraries Sergey et al. [PLDI’15] Atomic 
 Jayanti’s 
 Spin-lock Ticketed lock snapshot snapshot Flat combiner Abstract lock Allocator Snapshot client FC stack Treiber stack Increment Counting Exchanger network Abstract stack Sequential stack Concurrent Graph Quiescent 
 Quantitatively Manipulations Producer/Consumer client relaxed client

  39. 39 Functional Programming Ideas in… Teaching Software Engineering Research … for modularity and proof reuse

  40. 40 Functional Programming Ideas in… Teaching Software Engineering Research … for Modularity and Proof Reuse

  41. Algorithmic Competitions at UCL (2016-2018) • Targeting 2nd year undergrads, team work • One week-long • Should involve math and programming • Challenging for students, but easy to assess

  42. Algorithmic Competitions at UCL (2016-2018)

  43. The Competitions • 2016: Art Gallery Competition 
 • 2017: Move-and-Tag Competition 
 • 2018: Room Furnishing

  44. 
 Art Gallery Competition based on: 
 Chvátal’s Art Gallery Problem (1975)

  45. How many guards do we really need? The answer depends on the shape of the gallery.

  46. How many guards do we really need? The answer depends on the shape of the gallery.

  47. How many guards do we really need?

  48. How many guards do we really need?

  49. How many guards do we really need?

  50. How many guards do we really need?

  51. Art Gallery Problem For a given gallery (polygon), 
 find the minimal set of guards’ positions, 
 so together the guards can “see” the whole interior.

  52. Project: Art Gallery Competition Find the best solutions for a collection of large polygons. • 58 vertices • 5 guards

  53. Making it Fun • Problem generator; ‣ Polygons with different “features” (convex, rectangular, etc .) • Solution checker with online feedback ‣ geometric machinery (triangulation, visibility, …) ‣ web-server • Make sure that it all works.

  54. Making it Fun • Problem generator; ‣ Polygons with different “features” (convex, rectangular, etc .) • Solution checker with online feedback ‣ geometric machinery (triangulation, visibility, …) ‣ web-server • Make sure that it all works.

  55. Growing polygons Primitive polygons with specific “features”

  56. Growing polygons Seed

  57. Growing polygons

  58. Growing polygons

  59. Growing polygons

  60. Growing polygons

  61. Growing polygons

  62. Growing polygons

  63. 65 Can we enumerate “primitive” polygons 
 and plug arbitrary shapes generators?

  64. 66 The Essence of Functional Languages • Higher-order functions and closures • Purely functional data structures • Types and Type Inference • Pattern Matching • Polymorphism • Folds • Laziness • Continuations and CPS • Point-free style • Structural Recursion • Combinator Libraries • Type Classes • Algebraic Data Types • Monads

Recommend


More recommend