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

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

参照

関連したドキュメント

[9] DiBenedetto, E.; Gianazza, U.; Vespri, V.; Harnack’s inequality for degenerate and singular parabolic equations, Springer Monographs in Mathematics, Springer, New York (2012),

Despite the fact that the invari- ance of the Ising model with respect to the star-triangle transformation is very well known [2], we have not found in the literature a full proof

To establish two-sided heat kernel estimates for long range and non-uniformly elliptic conductance models with stable-like jumps, we will apply the localization argument for

It is also aimed to bring out the effect of body acceleration, stenosis shape parameter, yield stress, and pressure gradient on the physiologically important flow quantities such as

(ii) Due to singularity in the infinite cluster of long range percolation, [27] established the quenched invariance principle of the associated random walk in the sense of

For lack of analytical entropy selection, and also lack of structure profiles for complex physical systems, but indications on some relevant models, we can use the properties of

Therefore, reducing within Γ , we may end the internal blue line in a boundary dot and eliminate all other instances of the color blue since they become irrelevant double dots on

2) every structures and signature types have self variables; 3) paths are always prefixed by some self variable. Yet, our running examples do not follow these exactly. We assume