• 検索結果がありません。

Diagrammatic execution models for functional programming

N/A
N/A
Protected

Academic year: 2022

シェア "Diagrammatic execution models for functional programming"

Copied!
35
0
0

読み込み中.... (全文を見る)

全文

(1)

Muroya (RIMS, Kyoto U. & U. B’ham.)

Diagrammatic

execution models for functional programming

Koko Muroya

(RIMS, Kyoto University

& University of Birmingham)

Lambda World Cadiz 2018 (Cadiz), 25 October 2018

Steven W. T. Cheung Dan R. Ghica

(University of Birmingham)

(2)

Muroya (RIMS, Kyoto U. & U. B’ham.)

What happens when you run a functional program by hand?

2

(3)

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))

(4)

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-value evaluation

(5)

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

(6)

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-value evaluation

call-by-need (lazy)

evaluation

(7)

Muroya (RIMS, Kyoto U. & U. B’ham.)

Let’s run a functional program with a bit of formality...

7

(8)

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-value evaluation

(9)

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-value evaluation

(10)

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-value evaluation

(11)

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-value evaluation

(12)

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-value evaluation

(13)

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-value evaluation

(14)

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

(15)

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

(16)

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

(17)

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

(18)

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

(19)

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

(20)

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

(21)

Muroya (RIMS, Kyoto U. & U. B’ham.)

Now we use diagrams to run a functional program with formality!

21

(22)

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

(23)

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

(24)

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

(25)

Muroya (RIMS, Kyoto U. & U. B’ham.)

Goodness of diagrams

25

● name-free

● environment included

(26)

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

(27)

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

(28)

Muroya (RIMS, Kyoto U. & U. B’ham.)

More goodness of diagrams

28

(29)

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

(30)

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))

(31)

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 !

(32)

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

(33)

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=bZMSwo0zL io&t=130s

○ merge-sort vs. insert-sort

https://www.youtube.com/watch?v=U1NI-mWeN e0

● tail-recursion vs. non tail-recursion

https://www.youtube.com/watch?v=R4yCV5Ts1gk&t=1 4s

33

(34)

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

(35)

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

参照

関連したドキュメント

the full text of the 25 articles to identify ten features: a) the type of reading material, b) mate- rial size, c) text medium, d) duration of the program, e) institution where

t jump up right away, so they shook it a bit and since she still stayed seated—looking ahead at nobody—they just tipped her out of it like the way you get the cat off the seat if

For single population $\mathrm{m}\mathrm{o}\mathrm{d}\mathrm{e}\mathrm{l},\mathrm{w}\mathrm{e}$ show that the identical species can persist for

One of fundamental problems in $u\mathrm{d}\mathrm{a}\mathrm{a}\mathrm{e}\mathrm{i}\mathrm{c}\mathrm{a}1^{n}$ theories of models of arithmetic like Peano arithmetic

This program looks like a program with high quality, because it has showed no defect since the first print on the text of the course and while the author developed its network

Like the time-parallel NASA Space Program, the pioneers who developed and executed the Deep Sea Drilling Project from the deep-water coring success of CUSS-I in 1961 to the