functional in place update with layered datatype sharing
play

Functional In-place Update with Layered Datatype Sharing Michal - PowerPoint PPT Presentation

Functional In-place Update with Layered Datatype Sharing Michal Kone cn y LFCS, University of Edinburgh part of a wider collaboration with David Aspinall, Martin Hofmann, Robert Atkey M. Kone cn y, LFCS Edinburgh Theory seminar,


  1. Functional In-place Update with Layered Datatype Sharing Michal Koneˇ cn´ y LFCS, University of Edinburgh part of a wider collaboration with David Aspinall, Martin Hofmann, Robert Atkey M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 1

  2. Overview ✿✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿ • LFPL (Linear Functional Programming Language) [Hofmann 2000] • functional language ⇒ neat reasoning about programs • resource type ♦ ⇒ simple and efficient evaluation using heap M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 2

  3. Overview ✿✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿ • LFPL (Linear Functional Programming Language) [Hofmann 2000] • functional language ⇒ neat reasoning about programs • resource type ♦ ⇒ simple and efficient evaluation using heap • linear typing guarantees correctness of this evaluation forbids sharing on the heap M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 2

  4. Overview ✿✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿ • LFPL (Linear Functional Programming Language) [Hofmann 2000] • functional language ⇒ neat reasoning about programs • resource type ♦ ⇒ simple and efficient evaluation using heap • linear typing guarantees correctness of this evaluation forbids sharing on the heap • developing less restrictive typings for LFPL – usage aspects (Aspinall & Hofmann 2002) – explicit sharing in the context (Atkey) – layered datatype sharing (K 2002) • Scope: first-order, full recursion, arbitrary inductive datatypes M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 2

  5. Append in LFPL ✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿ ✿✿✿✿✿✿✿✿✿ ✿ In ML : append ( x, y ) = match x with Nil → y | Cons ( h, t ) → Cons ( h, append ( t, y )) h : A, t : L ( A ) ⊢ Cons ( h, t ) : L ( A ) M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 3

  6. Append in LFPL ✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿ ✿✿✿✿✿✿✿✿✿ ✿ In LFPL: append ( x, y ) = match x with Nil → y | Cons ( h, t ) @ d → Cons ( h, append ( t, y )) @ d h : A, t : L ( A ) , d : ♦ ⊢ Cons ( h, t ) @ d : L ( A ) elements of ♦ : units of heap space/heap locations M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 3

  7. � � � � � Append in LFPL ✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿ ✿✿✿✿✿✿✿✿✿ ✿ In LFPL: append ( x, y ) = match x with Nil → y | Cons ( h, t ) @ d → Cons ( h, append ( t, y )) @ d h : A, t : L ( A ) , d : ♦ ⊢ Cons ( h, t ) @ d : L ( A ) elements of ♦ : units of heap space/heap locations Heap representation: y x • • ������ ������ stack heap v 1 v 4 • • ������ ������ v 2 v 5 nil • ������ v 3 nil M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 3

  8. � � � � � � � � � � � Append in LFPL ✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿ ✿✿✿✿✿✿✿✿✿ ✿ In LFPL: append ( x, y ) = match x with Nil → y | Cons ( h, t ) @ d → Cons ( h, append ( t, y )) @ d h : A, t : L ( A ) , d : ♦ ⊢ Cons ( h, t ) @ d : L ( A ) elements of ♦ : units of heap space/heap locations Heap representation: y y x � r • • • • ������ ������ ������ ������ stack heap v 1 v 4 v 1 � v 4 • • • • ������ ������ ������ ������ � � � � v 2 v 5 nil v 2 v 5 nil • • � ������ ������ � � � � v 3 nil v 3 • � M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 3

  9. Non-linear typings ✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿ ✿ In LFPL: – Every use of a variable is considered destructive – No heap-sharing between arguments M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 4

  10. Non-linear typings ✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿ ✿ In LFPL: – Every use of a variable is considered destructive – No heap-sharing between arguments LFPL with Usage aspects (UAPL, Aspinall & Hofmann 2002): x : 1 L ( A ) , y : 2 L ( A ) ⊢ append ( x, y ) : L ( A ) x : 3 L ( A ) ⊢ length ( x ) : Nat 1 = destructive, 2 = read-only, 3 = read-only & not sharing with the result M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 4

  11. Non-linear typings ✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿ ✿ In LFPL: – Every use of a variable is considered destructive – No heap-sharing between arguments LFPL with Usage aspects (UAPL, Aspinall & Hofmann 2002): x : 1 L ( A ) , y : 2 L ( A ) ⊢ append ( x, y ) : L ( A ) x : 3 L ( A ) ⊢ length ( x ) : Nat 1 = destructive, 2 = read-only, 3 = read-only & not sharing with the result expression eval? LFPL append ( x, x ) N N Cons ( h, Cons ( h, t ) @ d1 ) @ d2 Y N Cons ( length ( x ) , x ) @ d Y N append ( Cons ( h, t1 ) @ d1, Y N Cons ( h, t2 ) @ d2 ) M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 4

  12. Non-linear typings ✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿ ✿ In LFPL: – Every use of a variable is considered destructive – No heap-sharing between arguments LFPL with Usage aspects (UAPL, Aspinall & Hofmann 2002): x : 1 L ( A ) , y : 2 L ( A ) ⊢ append ( x, y ) : L ( A ) x : 3 L ( A ) ⊢ length ( x ) : Nat 1 = destructive, 2 = read-only, 3 = read-only & not sharing with the result expression eval? LFPL UAPL append ( x, x ) N N N Cons ( h, Cons ( h, t ) @ d1 ) @ d2 Y N Y Cons ( length ( x ) , x ) @ d Y N Y append ( Cons ( h, t1 ) @ d1, Y N N Cons ( h, t2 ) @ d2 ) M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 4

  13. Non-linear typings ✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿ ✿ In LFPL: – Every use of a variable is considered destructive – No heap-sharing between arguments LFPL with Usage aspects (UAPL, Aspinall & Hofmann 2002): x : 1 L ( A ) , y : 2 L ( A ) ⊢ append ( x, y ) : L ( A ) x : 3 L ( A ) ⊢ length ( x ) : Nat 1 = destructive, 2 = read-only, 3 = read-only & not sharing with the result expression eval? LFPL UAPL DEEL append ( x, x ) N N N N Cons ( h, Cons ( h, t ) @ d1 ) @ d2 Y N Y Y Cons ( length ( x ) , x ) @ d Y N Y Y append ( Cons ( h, t1 ) @ d1, Y N N Y Cons ( h, t2 ) @ d2 ) M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 4

  14. � � � � � � � Datatype portions (layers) ✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿✿ L ( A ) = µX. Unit + ♦ ( A × X ) � x � = [[ ff , ff ] , [] , [ tt , ff ]] x • ����� stack heap • • ��������������������� ������ nil • ������ • � ff � � • nil �������������������� � � � � � � � � • � tt ff nil M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 5

  15. � � � � � � � Datatype portions (layers) ✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿✿ L ( A ) = µX. Unit + ♦ ( A × X ) � x � = [[ ff , ff ] , [] , [ tt , ff ]] x • ����� stack heap a • • ��������������������� ������ nil • ������ • � ff � � • nil �������������������� � � � � � � � � • � tt ff nil M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 5

  16. � � � � � � � Datatype portions (layers) ✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿✿ L ( A ) = µX. Unit + ♦ ( A × X ) � x � = [[ ff , ff ] , [] , [ tt , ff ]] x • ����� stack heap a • • ��������������������� ������ nil • ������ b • � ff � � • nil �������������������� � � � � � � � � • � tt ff nil M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 5

  17. � � � � � � � Datatype portions (layers) ✿✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿✿ L ( A ) = µX. Unit + ♦ ( A × X ) � x � = [[ ff , ff ] , [] , [ tt , ff ]] x • ����� stack x : L [ a ] ( L [ b ] ( Bool )) heap a • • ��������������������� ������ nil • ������ b • � ff � � • nil �������������������� � � � � � � � � • � tt ff nil M. Koneˇ cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend