Presentation is loading. Please wait.

Presentation is loading. Please wait.

DemeterF: Functions and Traversals in Combination

Similar presentations


Presentation on theme: "DemeterF: Functions and Traversals in Combination"— Presentation transcript:

1 DemeterF: Functions and Traversals in Combination
by Brian Chadwick

2 Introduction Do EoPL functions using functional transformations
Translate a class dictionary into a traverser (that works with a visitor) transformer (that works with function objects)

3 Default Transformer copy object
after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

4 Parameterize Default Transformer
PathSpec apply(J j) { return new Complement(j); } after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

5 Parameterize Default Transformer
PathSpec combine(J j, Boolean fn, Boolean sn) { return fn && sn; } PathSpec combine(Object j, Boolean fn, Boolean sn) { return fn && sn; } after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

6 Simple application Program transformation
Old E : Num | Var | Op | Call … Op : Plus | Equals. Equals = “=“. New E : … | Bool. Bool : True | False. class BoolTrans extends IDf { static E newtrue = Call.parse(“(= 1 1)”), static E newfalse= Call.parse(“(= 1 0) “); E apply(True t) {return newtrue; } E apply(False t) {return newfalse; } } apply for transformation of result returned by builder

7 de Bruijn indices Old New Var : Sym. Sym = Ident. Var : Sym | Addr.
for later de Bruijn indices Old Var : Sym. Sym = Ident. New Var : Sym | Addr. Addr = Integer. class AddrTrans extends IDf { Var apply(Var var, SymList senv) { return new Addr(senv.lookup(var));} } class SymExtender extends IDa { SymList update(Lambda l, SymList senv) { return senv.push(l.formals); }

8 The default Builder for PathSpec
after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

9 well-formed movie show how the default builder is modified to combine Boolean objects.

10 The default Builder for PathSpec well-formed specialization 1
#t: true #f: false after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J #t :J 5 2 :S :S :S :S 3 #t 7 #f 8 #t 4 #t

11 The default Builder for PathSpec well-formed specialization 2
#t: true #f: false after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J #t :J #t 5 2 :S :S :S :S #t 7 #f 8 #t 3 4 #t

12 The default Builder for PathSpec well-formed specialization 3
#t: true #f: false after blue arrow copy is built (like after) #t 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 3 #t 7 #f 8 #t 4 #t

13 The default Builder for PathSpec well-formed specialization 4
#t: true #f: false after blue arrow copy is built (like after) #t 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. #f 6 :J :J 5 2 :S :S :S :S 3 #t 7 #f 8 #t 4 #t

14 The default Builder for PathSpec well-formed specialization 5
#t: true #f: false after blue arrow copy is built (like after) #t 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. #f 6 :J #t :J 5 2 :S :S :S :S #t 7 #f 8 #t 3 4 #t

15 The default Builder for PathSpec well-formed specialization 6
#t: true #f: false after blue arrow copy is built (like after) #t 10 #f :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 3 #t 7 #f 8 #t 4 #t

16 The default Builder for PathSpec well-formed specialization 7
#t: true #f: false after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 3 #t 7 #f 8 #t 4 #t

17 The default Builder for PathSpec well-formed specialization
#t: true #f: false after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 #f 8 #t 3 #t 4 #t

18 The default Builder for PathSpec NOT_JOIN_MERGE specialization
after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

19 The default Builder for PathSpec NOT_JOIN_MERGE specialization
means a copy after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

20 The default Builder for PathSpec NOT_JOIN_MERGE specialization
after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

21 The default Builder for PathSpec NOT_JOIN_MERGE specialization
after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

22 The default Builder for PathSpec NOT_JOIN_MERGE specialization
after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

23 The default Builder for PathSpec NOT_JOIN_MERGE specialization
after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

24 The default Builder for PathSpec NOT_JOIN_MERGE specialization
after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

25 The default Builder for PathSpec NOT_JOIN_MERGE specialization
after blue arrow copy is built (like after) 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

26 The default Builder for PathSpec NOT_JOIN_MERGE specialization
insert NOT after blue arrow copy is built (like after) :N 10 :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

27 The default Builder for PathSpec NOT_JOIN_MERGE specialization
insert NOT :M after blue arrow copy is built (like after) :N 10 :N :M 1 9 Count only upon first visit (red) and upon final visit (blue). For leaf nodes, count only in red. 6 :J :J 5 2 :S :S :S :S 7 8 3 4

28 Illustration of combine for capacity constraint violation
19 :C (w1+w2+w3+w4,2) :Cons (w1+w2+w3+w4,1) :E (w4,0) 1 20 2 18a 3 18 3a 13a :Cons (w1+w2+w3,1) after blue arrow combine is active (like after) 17a :C (w2+w3,1) 4 12a 17 :Cons (w1,0) 5 13 14 12 16a :Cons (w2+w3,0) 15a 6 :E (w1,0) :Empty (0,0) 11a 7a 15 16 11 :E (w3,0) :Cons (w2,0) 8 both containers (C) violate capacity constraints 7 10a 9a :E (w2,0) :Empty (0,0) 9 10

29 Illustration of combine for capacity constraint violation
(w1+w2+w3+w4,2) :Cons (w1+w2+w3+w4,1) :E (w4,0) :Cons (w1+w2+w3,1) :C (w2+w3,1) :Cons (w1,0) :Cons (w2+w3,0) :E (w1,0) :Empty (0,0) :E (w3,0) :Cons (w2,0) both containers (C) violate capacity constraints :E (w2,0) :Empty (0,0)

30 Theory t[f,b](d) => d’, where d’=f(d), d is atomic
On left side of => the term c(…) only indicates a compound object. Theory f = apply b = combine t[f,b](d) => d’, where d’=f(d), d is atomic t[f,b](c(d0, … ,dn)) => f(b(c(d0, … ,dn), d’0, … ,d’n)), where d’i = t[f,b](di) Default functions: id[f](d) => d id[b](c(d0, … ,dn), d’0, … ,d’n) => c(d0, … ,dn) b[c](c(d0, … ,dn), d’0, … ,d’n) => c(d’0, … ,d’n)

31 Theory f is a polymorphic function that takes a single argument and returns a result. b is a function object that is responsible for reconstruction of data types.


Download ppt "DemeterF: Functions and Traversals in Combination"

Similar presentations


Ads by Google