automatic refunctionalization
play

Automatic Refunctionalization To a Language with Copattern Matching - PowerPoint PPT Presentation

Automatic Refunctionalization To a Language with Copattern Matching With Applications to the Expression Problem Tillmann Rendel Julia Trieflinger Klaus Ostermann University of Tbingen, Germany Two Core Aspects of FP 2/15 Two Core


  1. Automatic Refunctionalization To a Language with Copattern Matching With Applications to the Expression Problem Tillmann Rendel Julia Trieflinger Klaus Ostermann University of Tübingen, Germany

  2. Two Core Aspects of FP 2/15

  3. Two Core Aspects of FP programming with first-class functions ? ? ? infinite behavior black box to use, apply to values 2/15

  4. Two Core Aspects of FP programming with first-class functions ? ? ? ? ? ? infinite behavior black box to use, apply to values 2/15

  5. Two Core Aspects of FP programming with first-class functions ? ? ? ? ? ? infinite behavior black box to use, apply to values 2/15

  6. Two Core Aspects of FP programming with programming with first-class functions algebraic data types ? ? ? ? ? ? infinite behavior finite information black box known structure to use, apply to values to use, traverse structure 2/15

  7. Defunctionalization programs with first-class programs with defunctionalize functions data types [Reynolds, 1972] 3/15

  8. Defunctionalization programs with first-class image of defunctionalize functions defunct. programs with data types [Reynolds, 1972] 3/15

  9. Refunctionalization programs with first-class image of refunctionalize functions defunct. programs with data types [Danvy and Milliken, 2009] 4/15

  10. Wanted: Symmetric Languages programs with first-class image of functions defunct. programs with programs with codata types data types 5/15

  11. Language with Data Types ● data type declarations data Nat where zero() : Nat succ(Nat) : Nat ● first-order functions matching on first argument function add(Nat, Nat) : Nat where add(zero(), m ) = m add(succ( n ), m ) = succ(add( n , m )) 6/15

  12. Language with Data Types ● data type declarations data Nat where zero() : Nat succ(Nat) : Nat ● first-order functions matching on first argument function add(Nat, Nat) : Nat where add(zero(), m ) = m add(succ( n ), m ) = succ(add( n , m )) 6/15

  13. Language with Data Types ● data type declarations data Nat where zero() : Nat succ(Nat) : Nat ● first-order functions matching on first argument function add(Nat, Nat) : Nat where add(zero(), m ) = m add(succ( n ), m ) = succ(add( n , m )) 6/15

  14. Language with Data Types ● data type declarations data Nat where zero() : Nat succ(Nat) : Nat ● first-order functions matching on first argument function add(Nat, Nat) : Nat where add(zero(), m ) = m add(succ( n ), m ) = succ(add( n , m )) 6/15

  15. Language with Data Types ● data type declarations data Nat where zero() : Nat succ(Nat) : Nat ● first-order functions matching on first argument function add(Nat, Nat) : Nat where add(zero(), m ) = m add(succ( n ), m ) = succ(add( n , m )) 6/15

  16. Language with Data Types ● data type declarations data Nat where zero() : Nat succ(Nat) : Nat ● first-order functions matching on first argument function add(Nat, Nat) : Nat where add(zero(), m ) = m add(succ( n ), m ) = succ(add( n , m )) 6/15

  17. Language with Data Types ● data type declarations data Nat where zero() : Nat succ(Nat) : Nat ● first-order functions matching on first argument function add(Nat, Nat) : Nat where add(zero(), m ) = m add(succ( n ), m ) = succ(add( n , m )) 6/15

  18. Language with Data Types ● data type declarations data Nat where zero() : Nat succ(Nat) : Nat ● first-order functions matching on first argument function add(Nat, Nat) : Nat where add(zero(), m ) = m add(succ( n ), m ) = succ(add( n , m )) 6/15

  19. Language with Codata Types ● codata type declarations codata Stream where Stream.head() : Nat Stream.tail() : Stream ● first-order functions with copattern matching function repeat(Nat) : Stream where repeat( n ).head() = n repeat( n ).tail() = repeat( n ) 7/15

  20. Language with Codata Types ● codata type declarations codata Stream where Stream.head() : Nat Stream.tail() : Stream ● first-order functions with copattern matching function repeat(Nat) : Stream where repeat( n ).head() = n repeat( n ).tail() = repeat( n ) 7/15

  21. Language with Codata Types ● codata type declarations codata Stream where Stream.head() : Nat Stream.tail() : Stream ● first-order functions with copattern matching function repeat(Nat) : Stream where repeat( n ).head() = n repeat( n ).tail() = repeat( n ) 7/15

  22. Language with Codata Types ● codata type declarations codata Stream where Stream.head() : Nat Stream.tail() : Stream ● first-order functions with copattern matching function repeat(Nat) : Stream where repeat( n ).head() = n repeat( n ).tail() = repeat( n ) 7/15

  23. Language with Codata Types ● codata type declarations codata Stream where Stream.head() : Nat Stream.tail() : Stream ● first-order functions with copattern matching function repeat(Nat) : Stream where repeat( n ).head() = n repeat( n ).tail() = repeat( n ) 7/15

  24. Language with Codata Types ● codata type declarations codata Stream where Stream.head() : Nat Stream.tail() : Stream ● first-order functions with copattern matching function repeat(Nat) : Stream where repeat( n ).head() = n repeat( n ).tail() = repeat( n ) 7/15

  25. Language with Codata Types ● codata type declarations codata Stream where Stream.head() : Nat Stream.tail() : Stream ● first-order functions with copattern matching function repeat(Nat) : Stream where repeat( n ).head() = n repeat( n ).tail() = repeat( n ) 7/15

  26. Language with Codata Types ● codata type declarations codata Stream where Stream.head() : Nat Stream.tail() : Stream ● first-order functions with copattern matching function repeat(Nat) : Stream where repeat( n ).head() = n repeat( n ).tail() = repeat( n ) 7/15

  27. Language with Codata Types ● codata type declarations codata Stream where Stream.head() : Nat Stream.tail() : Stream ● first-order functions with copattern matching function repeat(Nat) : Stream where repeat( n ).head() = n repeat( n ).tail() = repeat( n ) 7/15

  28. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  29. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  30. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  31. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  32. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  33. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  34. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  35. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  36. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  37. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  38. Encoding First-Class Functions ● destructors with arguments codata Fun where Fun.apply(Nat) : Nat ● example: mapping over a stream function map(Stream, Fun) : Stream where map( s , f ).head() = f .apply( s .head()) map( s , f ).tail() = map( s .tail(), f ) 8/15

  39. (De|Re)functionalization refunctionalize defunctionalize ● data types codata types ● functions with patterns destructors ● constructors functions with copatterns 9/15

Recommend


More recommend