T HE C ALL-BY-NEED L AMBDA C ALCULUS, R EVISITED Stephen Chang and Matthias Felleisen Northeastern University 26/3/2012 �
Church ��
��
��
��
��
��
λ call-by-name (λx.e) e x → e{x:=e x } (β) �����
λ call-by-name E[(λx.e) e x ] → E[e{x:=e x }] (β) "leftmost-outermost" E @ λx e x e ��
λ v call-by-value E[(λx.e) v x ] → E[e{x:=v x }] (β v ) "leftmost-outermost" E @ λx v x e ��
call-by-need ��
call-by-need 1) Evaluate argument only when needed. ��
call-by-need 1) Evaluate argument only when needed. 2) Evaluate argument at most once. ��
λ need ? ? call-by-need 1) Evaluate argument only when needed. 2) Evaluate argument at most once. ��
λ need λ need-af λ need-mow ? ? = = Ariola/Felleisen Maraist/Odersky/Wadler '94,'95,'97 '94,'95,'98 call-by-need 1) Evaluate argument only when needed. 2) Evaluate argument at most once. ��
λ need λ need-af λ need-mow � � Ariola/Felleisen Maraist/Odersky/Wadler '94,'95,'97 '94,'95,'98 call-by-need 1) Evaluate argument only when needed. 2) Evaluate argument at most once. ��
λ need λ need-af λ need-mow � � Ariola/Felleisen Maraist/Odersky/Wadler '94,'95,'97 '94,'95,'98 call-by-need ��
λ need λ need-af λ need-mow � � Ariola/Felleisen Maraist/Odersky/Wadler '94,'95,'97 '94,'95,'98 call-by-need x ��
λ need λ need-af λ need-mow � � Ariola/Felleisen Maraist/Odersky/Wadler '94,'95,'97 '94,'95,'98 call-by-need λx x ��
λ need λ need-af λ need-mow � � Ariola/Felleisen Maraist/Odersky/Wadler '94,'95,'97 '94,'95,'98 call-by-need λx e x x ��
λ need λ need-af λ need-mow � � Ariola/Felleisen Maraist/Odersky/Wadler '94,'95,'97 '94,'95,'98 call-by-need → → @ λx e x λx e x x x (reshuffle) ��
λ need λ need-af λ need-mow � � Ariola/Felleisen Maraist/Odersky/Wadler '94,'95,'97 '94,'95,'98 call-by-need @ @ → λx v x λx v x x v x (like β) ���
our λ need call-by-need λx e x x ���
our λ need call-by-need λx e x x ���
our λ need call-by-need λx "demand path" e x x ���
our λ need call-by-need λx "demand path" e x x (β need ) ���
O LD λ need : O PERATIONAL O VERVIEW 1) Find the next demanded variable. 2) Find its corresponding argument and evaluate it. 3) Substitute evaluated argument for demanded variable. ���
O LD λ need : O PERATIONAL O VERVIEW 1) Find the next demanded variable. 2) Find its corresponding argument and evaluate it. 3) Substitute evaluated argument for demanded variable. ���
O LD λ need : D EMAND C ONTEXTS D = [ ] | D e ���
O LD λ need : D EMAND C ONTEXTS D = [ ] | D e ���
O LD λ need : D EMAND C ONTEXTS D = [ ] | D e | (λx.D) e ���
O LD λ need : D EMAND C ONTEXTS D = [ ] | D e | (λx.D) e ���
O LD λ need : D EMAND C ONTEXTS D = [ ] | D e | (λx.D) e ���
O LD λ need : D EMAND C ONTEXTS D = [ ] | D e | (λx.D) e binding structure ���
O LD λ need : D EMAND C ONTEXTS D = [ ] | D e | B[D] binding structure B = [ ] | (λx.B) e ���
O LD λ need : B INDING S TRUCTURE B = [ ] | (λx.B) e (λx.(λy.(λz. ...) e z ) e y ) e x ���
O LD λ need : B INDING S TRUCTURE B = [ ] | (λx.B) e (λx.(λy.(λz. ...) e z ) e y ) e x ���
O LD λ need : B INDING S TRUCTURE B = [ ] | (λx.B) e (λx.(λy.(λz. ...) e z ) e y ) e x ���
O LD λ need : B INDING S TRUCTURE B = [ ] | (λx.B) e (λx.(λy.(λz. ...) e z ) e y ) e x @ λx e x @ λy e y @ λz e z ... ���
O LD λ need : R ESHUFFLING OF B INDINGS B = [ ] | (λx.B) e (((λx.λy.λz. ...) e x ) e y ) e z @ @ e z @ e y λx e x λy λz ... ���
O LD λ need : R ESHUFFLING OF B INDINGS B = [ ] | (λx.B) e (((λx.λy.λz. ...) e x ) e y ) e z @ @ e z @ e y λx e x λy λz ... ���
O LD λ need : R ESHUFFLING OF B INDINGS B = [ ] | (λx.B) e (((λx.λy.λz. ...) e x ) e y ) e z @ @ e z @ e y λx e x λy λz ... ���
O LD λ need : R ESHUFFLING OF B INDINGS B = [ ] | (λx.B) e ((λx.(λy.λz. ...) e y ) e x ) e z @ @ e z λx e x @ λy e y λz ... ���
O LD λ need : R ESHUFFLING OF B INDINGS B = [ ] | (λx.B) e ((λx.(λy.λz. ...) e y ) e x ) e z @ @ e z λx e x @ λy e y λz ... ���
O LD λ need : R ESHUFFLING OF B INDINGS B = [ ] | (λx.B) e (λx.((λy.λz. ...) e y ) e z ) e x @ λx e x @ @ e z λy e y λz ... ���
O LD λ need : R ESHUFFLING OF B INDINGS B = [ ] | (λx.B) e (λx.((λy.λz. ...) e y ) e z ) e x @ λx e x @ @ e z λy e y λz ... ���
O LD λ need : R ESHUFFLING OF B INDINGS B = [ ] | (λx.B) e (λx.(λy.(λz. ...) e z ) e y ) e x @ λx e x @ λy e y @ λz e z ... ���
P ROBLEMS WITH O LD C ALL-BY-NEED C ALCULUS 1) Reshuffling rules. ���
O LD λ need : O PERATIONAL O VERVIEW 1) Find the next demanded variable. 2) Find its corresponding argument and evaluate it. 3) Substitute evaluated argument for demanded variable. ���
O LD λ need : O PERATIONAL O VERVIEW 1) Find the next demanded variable. 2) Find its corresponding argument and evaluate it. 3) Substitute evaluated argument for demanded variable. ���
O LD λ need : O PERATIONAL O VERVIEW 1) Find the next demanded variable. 2) Find its corresponding argument and evaluate it. 3) Substitute evaluated argument for demanded variable. ���
O LD λ need : D EREFERENCING (λx.(λy.(λz. ...) e z ) e y ) e x @ λx e x @ λy e y @ λz e z ... ���
O LD λ need : D EREFERENCING (λx.(λy.(λz. y ) e z ) e y ) e x @ λx e x @ λy e y @ λz e z y ���
O LD λ need : D EREFERENCING (λx.(λy.(λz. y ) e z ) v y ) e x @ λx e x @ λy v y @ λz e z y ���
O LD λ need : D EREFERENCING (λx.(λy.(λz. y ) e z ) v y ) e x @ λx e x @ λy v y @ λz e z y (λy.D[y]) v → (λy.D[v]) v (deref) ���
O LD λ need : D EREFERENCING (λx.(λy.(λz. v y ) e z ) v y ) e x @ λx e x @ λy v y @ λz e z v y (λy.D[y]) v → (λy.D[v]) v (deref) ���
P ROBLEMS WITH O LD C ALL-BY-NEED C ALCULUS 1) Reshuffling rules. 2) Arguments and applications never go away. ���
N EW λ need : H ANDLING A RBITRARY B INDING S TRUCTURE @ λx e x @ λy e y @ λz e z ... �������
N EW λ need : H ANDLING A RBITRARY B INDING S TRUCTURE @ λx e x @ λy e y @ λz e z ... B = [ ] | (λx.B) e ���
N EW λ need : H ANDLING A RBITRARY B INDING S TRUCTURE @ @ e z @ e y λx e x λy λz ... A = [ ] | ??? ���
N EW λ need : H ANDLING A RBITRARY B INDING S TRUCTURE @ λx e x @ @ e z λy e y λz ... A = [ ] | ??? ���
N EW λ need : H ANDLING A RBITRARY B INDING S TRUCTURE @ @ e z λx e x @ λy e y λz ... A = [ ] | ??? ���
N EW λ need : H ANDLING A RBITRARY B INDING S TRUCTURE @ @ e z λx e x @ λy e y λz ... A = [ ] | (λx.A) e ���
N EW λ need : H ANDLING A RBITRARY B INDING S TRUCTURE @ @ e z λx e x @ λy e y λz ... A = [ ] | (λx.A) e ���
N EW λ need : H ANDLING A RBITRARY B INDING S TRUCTURE @ @ e z λx e x @ λy e y λz ... A = [ ] | (λx.A) e ���
N EW λ need : H ANDLING A RBITRARY B INDING S TRUCTURE @ @ e z λx e x @ λy e y λz ... A = [ ] | A[(λx.A)] e ���
N EW λ need : H ANDLING A RBITRARY B INDING S TRUCTURE @ @ e z λx e x @ λy e y λz ... A = [ ] | A[(λx.A)] e D = [ ] | D e | A[D] ���
P ROBLEMS WITH O LD C ALL-BY-NEED C ALCULUS 1) Reshuffling rules. 2) Arguments and applications never go away. ���
N EW λ need : S PLITTING C ONTEXTS @ @ e z @ e y λx e x λy λz ... ���
N EW λ need : S PLITTING C ONTEXTS @ @ e z @ e y λx e x λy λz ... A[ ...] ���
N EW λ need : S PLITTING C ONTEXTS @ @ e z @ e y λx e x λy λz D[y] A[D[y]] ���
N EW λ need : S PLITTING C ONTEXTS @ @ e z @ e y λx e x λy λz D[y] A[D[y]] ���
N EW λ need : S PLITTING C ONTEXTS @ @ e z @ e y λx e x λy λz D[y] ... (λy...D[y])...e y ... ���
N EW λ need : S PLITTING C ONTEXTS @ @ e z @ e y λx e x λy λz D[y] ... (λy...D[y])...e y ... ���
N EW λ need : S PLITTING C ONTEXTS @ @ e z @ e y λx e x λy λz D[y] ...A[λy...D[y] ] e y ... ���
N EW λ need : S PLITTING C ONTEXTS @ @ e z @ e y λx e x λy λz D[y] ...A[λy...D[y] ] e y ... ���
N EW λ need : S PLITTING C ONTEXTS @ @ e z @ e y λx e x λy λz D[y] ...A[λy. [D[y]]] e y ... = [ ] | A[λx. ] ���
Recommend
More recommend