![Page 1: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/1.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
Diagrammaticexecution models for
functional programmingKoko Muroya
(RIMS, Kyoto University& University of Birmingham)
Lambda World Cadiz 2018 (Cadiz), 25 October 2018
Steven W. T. CheungDan R. Ghica
(University of Birmingham)
![Page 2: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/2.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
What happens when you run a functional program by hand?
2
![Page 3: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/3.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
(* computing the identity function in OCaml *)(fun _ -> fun x -> fun x) ((fun y -> y) (fun z -> z))
-- computing the identity function in Haskell(\_ -> \x -> x) ((\y -> y) (\z -> z))
Running a functional program by hand
3
(λw. λx. x) ((λy. y) (λz. z))
![Page 4: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/4.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
(* computing the identity function in OCaml *)(fun _ -> fun x -> fun x) ((fun y -> y) (fun z -> z))
(* (fun _ -> fun x -> x) ((fun y -> y) (fun z -> z)) *) (* => (fun _ -> fun x -> x) (fun z -> z) *) (* => fun x -> x *)
Running a functional program by hand
4
call-by-valueevaluation
![Page 5: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/5.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
-- computing the identity functionin Haskell(\_ -> \x -> x) ((\y -> y) (\z -> z))
-- (\_ -> \x -> x) ((\y -> y) (\z -> z)) -- => \x -> x
Running a functional program by hand
5
call-by-need(lazy)
evaluation
![Page 6: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/6.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
Same result,
but different steps!
(* computing the identity function in OCaml *)(fun _ -> fun x -> fun x) ((fun y -> y) (fun z -> z))
(* (fun _ -> fun x -> x) ((fun y -> y) (fun z -> z)) *) (* => (fun _ -> fun x -> x) (fun z -> z) *) (* => fun x -> x *)
-- computing the identity functionin Haskell(\_ -> \x -> x) ((\y -> y) (\z -> z))
-- (\_ -> \x -> x) ((\y -> y) (\z -> z)) -- => \x -> x
Running a functional program by hand
6
call-by-valueevaluation
call-by-need (lazy)
evaluation
![Page 7: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/7.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
Let’s run a functional program with a bit of formality...
7
![Page 8: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/8.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of configuration
Running a functional program, formally
8
● program● “focus”
(* computing the identity function in OCaml *)
(fun _ -> fun x -> fun x) ((fun y -> y) (fun z -> z))
call-by-valueevaluation
![Page 9: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/9.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of configuration
Running a functional program, formally
9
● program● “focus”
(* computing the identity function in OCaml *)
(fun _ -> fun x -> fun x) ((fun y -> y) (fun z -> z))
call-by-valueevaluation
![Page 10: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/10.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of configuration
Running a functional program, formally
10
● program● “focus”
(* computing the identity function in OCaml *)
(fun _ -> fun x -> fun x) ((fun y -> y) (fun z -> z))
call-by-valueevaluation
![Page 11: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/11.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of configuration
Running a functional program, formally
11
● program● “focus”
(* computing the identity function in OCaml *)
(fun _ -> fun x -> fun x) (fun z -> z)
call-by-valueevaluation
![Page 12: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/12.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of configuration
Running a functional program, formally
12
● program● “focus”
(* computing the identity function in OCaml *)
(fun _ -> fun x -> fun x) (fun z -> z)
call-by-valueevaluation
![Page 13: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/13.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of configuration
Running a functional program, formally
13
● program● “focus”
(* computing the identity function in OCaml *)
fun x -> fun x
call-by-valueevaluation
![Page 14: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/14.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of configuration
Running a functional program, formally
14
● program● “focus”
-- computing the identity functionin Haskell(\_ -> \x -> x) ((\y -> y) (\z -> z))
call-by-need(lazy)
evaluation
![Page 15: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/15.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of configuration
Running a functional program, formally
15
● program● “focus”
-- computing the identity functionin Haskell(\_ -> \x -> x) ((\y -> y) (\z -> z))
call-by-need(lazy)
evaluation
![Page 16: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/16.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of configuration
Running a functional program, formally
16
● program● “focus”
-- computing the identity functionin Haskell\x -> x
call-by-need(lazy)
evaluation
![Page 17: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/17.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of configuration
Running a functional program, formally
17
(* computing the identity function in OCaml *)(fun _ -> fun x -> fun x) ((fun y -> y) (fun z -> z))
(* (fun _ -> fun x -> x) ((fun y -> y) (fun z -> z)) *) (* => (fun _ -> fun x -> x) ((fun y -> y) (fun z -> z)) *) (* => (fun _ -> fun x -> x) (fun z -> z) *) (* => (fun _ -> fun x -> x) (fun z -> z) *) (* => fun x -> x *)
-- computing the identity function in Haskell(\_ -> \x -> x) ((\y -> y) (\z -> z))
-- (\_ -> \x -> x) ((\y -> y) (\z -> z)) -- => \x -> x
● program● “focus” determining
evaluation strategy
![Page 18: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/18.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)18
prove program equivalence (validate compiler optimisations)
● “When are two programs the same?”● result modelled by observable transitions & final
configuration
Goodness of formality
![Page 19: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/19.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)19
prove program equivalence (validate compiler optimisations)
● “When are two programs the same?”● result modelled by observable transitions & final
configuration
analyse execution cost
● “How much time/space does it take to run a program?”● time cost modelled by number and cost of transitions● space cost modelled by size of configurations
Goodness of formality
![Page 20: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/20.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)20
prove program equivalence (validate compiler optimisations)
● “When are two programs the same?”● result modelled by observable transitions & final
configuration
analyse execution cost
● “How much time/space does it take to run a program?”● time cost modelled by number and cost of transitions● space cost modelled by size of configurations
guarantee “correctness” of implementation
● “Does a compiler work as intended?”● implementation derived as abstract machine
Goodness of formality
![Page 21: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/21.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
Now we use diagrams to run a functional program with formality!
21
![Page 22: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/22.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)22
running a program by
change of configuration
Conventional approaches
running a program by
change of diagram configuration
Diagrammatic approach
● diagram representation of program● “token” determining evaluation
strategy
● program● “focus” determining
evaluation strategy
![Page 23: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/23.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of diagram configuration
Running a functional program with diagrams
23
● diagram representation of program
● “token” determining evaluation strategy
name-free
![Page 24: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/24.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
by change of diagram configuration
[DEMO]
On-line visualiser for lambda-calculus
https://koko-m.github.io/GoI-Visualiser/
● call-by-name, call-by-need (lazy)● call-by-value: left-to-right, right-to-left
Running a functional program with diagrams
24
● diagram representation of program
● “token” determining evaluation strategy
name-free
![Page 25: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/25.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
Goodness of diagrams
25
● name-free● environment
included
![Page 26: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/26.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
visualise interesting properties of programs
● call-by-value vs. call-by-need (lazy)● on-demand copying with intermediate sharing● patterns in divergence
○ (λx. x x) (λx. x x)○ (λx. x x x) (λx. x x x)
Goodness of diagrams
26
● name-free● environment
included
![Page 27: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/27.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
visualise interesting properties of programs
● call-by-value vs. call-by-need (lazy)● on-demand copying with intermediate sharing● patterns in divergence
○ (λx. x x) (λx. x x)○ (λx. x x x) (λx. x x x)
answer (conventional) questions from new perspectives
● “When are two programs the same?”● “How much time/space does it take to run a program?”● “Does a compiler work as intended?”
Goodness of diagrams
27
● name-free● environment
included
![Page 28: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/28.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
More goodness of diagrams
28
![Page 29: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/29.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
support textual-and-visual programming
guide language design for unconventional/new programming paradigms (to be presented by Steven)
More goodness of diagrams
29
![Page 30: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/30.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
Towards textual-and-visual programming
30
“We’d like not just text or diagram, but both!”
textual program
diagrammatical program
(λw. λx. x) ((λy. y) (λz. z))
![Page 31: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/31.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
Towards textual-and-visual programming
31
“We’d like not just text or diagram, but both!”
textual program
diagrammatical program
(λw. λx. x) ((λy. y) (λz. z))
✔(grammar) form / edit ?
(validity criteria)
✔ execute ✔
✔ debug !
![Page 32: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/32.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
OCaml Visual Debugger
https://fyp.jackhughesweb.com/ by Jack Hughes
for a subset of OCaml
● arithmetic (int), comparison (bool)● conditional (if), recursion (let rec)● lists, pairs● pattern-matching
features
● interactive diagram view● go forwards/backwards & pause/resume & jump steps● breakpoint on diagram● stats
32
![Page 33: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/33.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
OCaml Visual Debugger
visualise interesting properties of programs
● sorting algorithms comparison○ bubble-sort vs. insert-sort
https://www.youtube.com/watch?v=bZMSwo0zLio&t=130s
○ merge-sort vs. insert-sort https://www.youtube.com/watch?v=U1NI-mWeNe0
● tail-recursion vs. non tail-recursion https://www.youtube.com/watch?v=R4yCV5Ts1gk&t=14s
33
![Page 34: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/34.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
support textual-and-visual programming
● “We’d like not just text or diagram, but both!”● We’ve got OCaml Visual Debugger● … and want a text-and-diagram editor!
guide language design for unconventional/new programming paradigms (to be presented by Steven)
More goodness of diagrams
34
![Page 35: Diagrammatic (RIMS, Kyoto University execution models ...kxm538/talks/lambdaworld18.pdf · Muroya (RIMS, Kyoto U. & U. B’ham.) Diagrammatic execution models for functional programming](https://reader033.vdocuments.site/reader033/viewer/2022041812/5e581c965aacc027bf18f2f4/html5/thumbnails/35.jpg)
Muroya (RIMS, Kyoto U. & U. B’ham.)
support textual-and-visual programming
● “We’d like not just text or diagram, but both!”● We’ve got OCaml Visual Debugger● … and want a text-and-diagram editor!
guide language design for unconventional/new programming paradigms (to be presented by Steven)
More goodness of diagrams
35