SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
Property Based Dispatch
                                                                 in Functional Languages




     Property Based Dispatch in Functional                         Introduction

                                                                   Olena Properties
                  Languages                                        Lisp
                                                                   Implementation

                                                                   Other Languages

                                                                   Conclusion
                  Christopher Chedeau
                                 LRDE
          Laboratoire de Recherche et D´veloppement d’EPITA
                                       e


                       January 18, 2012



                 http://lrde.epita.fr/


1 / 19                                                        Christopher Chedeau
Property Based Dispatch
                            in Functional Languages




   Introduction               Introduction

                              Olena Properties

                              Lisp
                              Implementation
   Olena Properties
                              Other Languages

                              Conclusion

   Lisp Implementation


   Other Languages


   Conclusion




2 / 19                   Christopher Chedeau
Property Based Dispatch
                                                       in Functional Languages
 Olena Properties
                                                         Introduction

                                                         Olena Properties

                                                         Lisp
                                                         Implementation

                                                         Other Languages

                                                         Conclusion
      Type Name        Values
     image dimension   any, one d, two d, three d




3 / 19                                              Christopher Chedeau
Property Based Dispatch
                                                               in Functional Languages
 Shift Algorithm
                                                                 Introduction

                                                                 Olena Properties

                                                                 Lisp
                                                                 Implementation

                                                                 Other Languages

                                                                 Conclusion



                                       definition
                              any unique multiple varying
         Specialization (1)
         Specialization (2)

                                            size
                                         any fixed
                    Specialization (1)
                    Specialization (2)
4 / 19                                                      Christopher Chedeau
Property Based Dispatch
                                                                   in Functional Languages
 C++ Implementation
   shift(Window<W>& win, mln dpsite(W)& dp) {                        Introduction

                                                                     Olena Properties
     // Dispatch on definition property
                                                                     Lisp
     shift (mln trait window definition(W)(), exact(win), dp);        Implementation

   }                                                                 Other Languages

                                                                     Conclusion

   shift (trait::window::definition::unique,
          W& win, mln dpsite(W)& dp) {
     /* Specialized implementation (1) */
   }

   shift (trait::window::definition::multiple,
          W& win, mln dpsite(W)& dp) {
     /* Specialized implementation (2) */
   }


5 / 19                                                          Christopher Chedeau
Property Based Dispatch
                                                           in Functional Languages
 Shift Algorithm
                                                             Introduction

                                                             Olena Properties

                                   definition                 Lisp
                                                             Implementation
                          any unique multiple varying
     Specialization (1)   Ö             Ö        Ö           Other Languages


                          Ö     Ö                Ö
                                                             Conclusion
     Specialization (2)

                             size
                          any fixed
     Specialization (1)   Ö
     Specialization (2)




6 / 19                                                  Christopher Chedeau
Property Based Dispatch
                                                                       in Functional Languages
 C++ Implementation
   shift(Window<W>& win, mln dpsite(W)& dp) {                            Introduction

                                                                         Olena Properties
     mlc is not(mln trait window definition(W),
                                                                         Lisp
             trait::window::definition::any)::check();                    Implementation

     mlc is not(mln trait window definition(W),                           Other Languages

             trait::window::definition::varying)::check();                Conclusion



         shift (mln trait window definition(W)(), exact(win), dp);
   }

   shift (trait::window::definition::unique,
          W& win, mln dpsite(W)& dp) {
     mlc is(mln trait window size(W),
              trait::window::size::fixed)::check();
   }


7 / 19                                                              Christopher Chedeau
Property Based Dispatch
                                                        in Functional Languages
 Lisp Implementation
                                                          Introduction

                                                          Olena Properties

                                                          Lisp
                                                          Implementation

                                                          Other Languages
   (defmethod shift (       (defmethod shift (
                                                          Conclusion
     (win window)             (win window)
     (dp dpsite))             (dp dpsite))
     ; Specialization (1)     ; Specialization (2)
   )                        )




8 / 19                                               Christopher Chedeau
Property Based Dispatch
                                                                 in Functional Languages
 Lisp Implementation
                                                                   Introduction

                                                                   Olena Properties

                                                                   Lisp
   (defalgo shift (            (defalgo shift (                    Implementation

     (win                        (win                              Other Languages

                                                                   Conclusion
        :properties (               :properties (
          :definition :unique          :definition :multiple)
          :size :fixed)              window)
        window)                  (dp dpsite))
     (dp dpsite))                ; Specialization (2)
     ; Specialization (1)      )
   )




9 / 19                                                        Christopher Chedeau
Property Based Dispatch
                               in Functional Languages
  Implementation Overview
                                 Introduction

                                 Olena Properties

                                 Lisp
                                 Implementation

                                 Other Languages

                                 Conclusion




10 / 19                     Christopher Chedeau
Property Based Dispatch
                                    in Functional Languages
  Fibonacci
                                      Introduction

                                      Olena Properties
    (defalgo fibo ((n
                                      Lisp
        (lambda (n) (< n 2))))        Implementation

      n)                              Other Languages

                                      Conclusion




11 / 19                          Christopher Chedeau
Property Based Dispatch
                                    in Functional Languages
  Fibonacci
                                      Introduction

                                      Olena Properties
    (defalgo fibo ((n
                                      Lisp
        (lambda (n) (< n 2))))        Implementation

      n)                              Other Languages

                                      Conclusion



    (defun <2 (n) (< n 2))
    (defalgo fibo ((n #’<2))
      n)




11 / 19                          Christopher Chedeau
Property Based Dispatch
                                                                in Functional Languages
  Fibonacci
                                                                  Introduction

                                                                  Olena Properties
    (defalgo fibo ((n             (defun is (a)
                                                                  Lisp
        (lambda (n) (< n 2))))     (lambda (b)                    Implementation

      n)                              (eq a b)))                  Other Languages

                                                                  Conclusion

                                 (defalgo fibo ((n (is 0)))
    (defun <2 (n) (< n 2))         0)
    (defalgo fibo ((n #’<2))      (defalgo fibo ((n (is 1)))
      n)                           1)




11 / 19                                                      Christopher Chedeau
Property Based Dispatch
                                                                in Functional Languages
  Fibonacci
                                                                  Introduction

                                                                  Olena Properties
    (defalgo fibo ((n             (defun is (a)
                                                                  Lisp
        (lambda (n) (< n 2))))     (lambda (b)                    Implementation

      n)                              (eq a b)))                  Other Languages

                                                                  Conclusion

                                 (defalgo fibo ((n (is 0)))
    (defun <2 (n) (< n 2))         0)
    (defalgo fibo ((n #’<2))      (defalgo fibo ((n (is 1)))
      n)                           1)


    (defalgo fibo (n)
      (+ (fibo (− n 2)) (fibo (− n 1))))



11 / 19                                                      Christopher Chedeau
Property Based Dispatch
                                          in Functional Languages
  Javascript Full Dispatch
                                            Introduction

                                            Olena Properties

                                            Lisp
                                            Implementation
    fibo = FullDispatch()                    Other Languages

                                            Conclusion
    fibo.add [(n) −> n < 2],
      (n) −> n

    fibo.add [null],
      (n) −> fibo(n − 1) + fibo(n − 2)




12 / 19                                Christopher Chedeau
Property Based Dispatch
                                            in Functional Languages
  Python Decorators
                                              Introduction

                                              Olena Properties

                                              Lisp
                                              Implementation
    @dispatch(inside(0, 1))                   Other Languages
    def fibo(n):                               Conclusion
        return n

    @dispatch(int)
    def fibo(n):
        return fibo(n − 1) + fibo(n − 2)




13 / 19                                  Christopher Chedeau
Property Based Dispatch
                                           in Functional Languages
  Haskell Pattern Matching
                                             Introduction

                                             Olena Properties

                                             Lisp
                                             Implementation

                                             Other Languages

                                             Conclusion
    fibo 0 = 0
    fibo 1 = 1
    fibo n = fibo (n − 1) + fibo (n − 2)




14 / 19                                 Christopher Chedeau
Property Based Dispatch
                                            in Functional Languages
  MOP
                                              Introduction

                                              Olena Properties

                                              Lisp
                                              Implementation
    (defmethod fibo (n)
                                              Other Languages
      (+ (fibo (− n 1)) (fibo (− n 2))))
                                              Conclusion


    (defmethod fibo ((n (eql 1)))
      n)

    (defmethod fibo ((n (eql 0)))
      n)




15 / 19                                  Christopher Chedeau
Property Based Dispatch
                                                                 in Functional Languages
  Filtered Dispatch
                                                                   Introduction

                                                                   Olena Properties

    (defun state (n)                                               Lisp
                                                                   Implementation
      (if (< n 2)
                                                                   Other Languages
         ’terminal                                                 Conclusion
         ’general))

    (defmethod fibo :filter :state ((n (eql ’terminal)))
      n)

    (defmethod factorial :filter :state ((n (eql ’general)))
      (+ (fibo (− n 1)) (fibo (− n 2))))




16 / 19                                                       Christopher Chedeau
Property Based Dispatch
                                             in Functional Languages
  Multimethod.js
                                               Introduction

                                               Olena Properties

                                               Lisp
    fibo = multimethod()                        Implementation

      .dispatch((n) −> if n < 2                Other Languages

           ’terminal’                          Conclusion

        else
           ’general’)
      .when(’terminal’,
        (n) −> n)
      .when(’general’,
        (n) −> fibo(n − 1) + fibo(n − 2))




17 / 19                                   Christopher Chedeau
Property Based Dispatch
                          in Functional Languages
  Conclusion
                            Introduction

                            Olena Properties

                            Lisp
                            Implementation

                            Other Languages

                            Conclusion


          Conclusion




18 / 19                Christopher Chedeau
Property Based Dispatch
                   in Functional Languages
  Questions ?
                     Introduction

                     Olena Properties

                     Lisp
                     Implementation

                     Other Languages

                     Conclusion




19 / 19         Christopher Chedeau

Contenu connexe

Plus de Christopher Chedeau

Generic Image Processing With Climb – 5th ELS
Generic Image Processing With Climb – 5th ELSGeneric Image Processing With Climb – 5th ELS
Generic Image Processing With Climb – 5th ELSChristopher Chedeau
 
Climb - Property-based dispatch in functional languages [Report]
Climb - Property-based dispatch in functional languages [Report]Climb - Property-based dispatch in functional languages [Report]
Climb - Property-based dispatch in functional languages [Report]Christopher Chedeau
 
JSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into JavascriptJSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into JavascriptChristopher Chedeau
 
Climb – Chaining Operators - Report
Climb – Chaining Operators - ReportClimb – Chaining Operators - Report
Climb – Chaining Operators - ReportChristopher Chedeau
 
Climb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingClimb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingChristopher Chedeau
 
Climb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingClimb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingChristopher Chedeau
 

Plus de Christopher Chedeau (9)

Generic Image Processing With Climb – 5th ELS
Generic Image Processing With Climb – 5th ELSGeneric Image Processing With Climb – 5th ELS
Generic Image Processing With Climb – 5th ELS
 
Climb - Property-based dispatch in functional languages [Report]
Climb - Property-based dispatch in functional languages [Report]Climb - Property-based dispatch in functional languages [Report]
Climb - Property-based dispatch in functional languages [Report]
 
JSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into JavascriptJSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into Javascript
 
J
JJ
J
 
Morpho math
Morpho mathMorpho math
Morpho math
 
Slides
SlidesSlides
Slides
 
Climb – Chaining Operators - Report
Climb – Chaining Operators - ReportClimb – Chaining Operators - Report
Climb – Chaining Operators - Report
 
Climb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingClimb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image Processing
 
Climb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingClimb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image Processing
 

Dernier

Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Dernier (20)

Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 

Climb - Property-based dispatch in functional languages [Slides]

  • 1. Property Based Dispatch in Functional Languages Property Based Dispatch in Functional Introduction Olena Properties Languages Lisp Implementation Other Languages Conclusion Christopher Chedeau LRDE Laboratoire de Recherche et D´veloppement d’EPITA e January 18, 2012 http://lrde.epita.fr/ 1 / 19 Christopher Chedeau
  • 2. Property Based Dispatch in Functional Languages Introduction Introduction Olena Properties Lisp Implementation Olena Properties Other Languages Conclusion Lisp Implementation Other Languages Conclusion 2 / 19 Christopher Chedeau
  • 3. Property Based Dispatch in Functional Languages Olena Properties Introduction Olena Properties Lisp Implementation Other Languages Conclusion Type Name Values image dimension any, one d, two d, three d 3 / 19 Christopher Chedeau
  • 4. Property Based Dispatch in Functional Languages Shift Algorithm Introduction Olena Properties Lisp Implementation Other Languages Conclusion definition any unique multiple varying Specialization (1) Specialization (2) size any fixed Specialization (1) Specialization (2) 4 / 19 Christopher Chedeau
  • 5. Property Based Dispatch in Functional Languages C++ Implementation shift(Window<W>& win, mln dpsite(W)& dp) { Introduction Olena Properties // Dispatch on definition property Lisp shift (mln trait window definition(W)(), exact(win), dp); Implementation } Other Languages Conclusion shift (trait::window::definition::unique, W& win, mln dpsite(W)& dp) { /* Specialized implementation (1) */ } shift (trait::window::definition::multiple, W& win, mln dpsite(W)& dp) { /* Specialized implementation (2) */ } 5 / 19 Christopher Chedeau
  • 6. Property Based Dispatch in Functional Languages Shift Algorithm Introduction Olena Properties definition Lisp Implementation any unique multiple varying Specialization (1) Ö Ö Ö Other Languages Ö Ö Ö Conclusion Specialization (2) size any fixed Specialization (1) Ö Specialization (2) 6 / 19 Christopher Chedeau
  • 7. Property Based Dispatch in Functional Languages C++ Implementation shift(Window<W>& win, mln dpsite(W)& dp) { Introduction Olena Properties mlc is not(mln trait window definition(W), Lisp trait::window::definition::any)::check(); Implementation mlc is not(mln trait window definition(W), Other Languages trait::window::definition::varying)::check(); Conclusion shift (mln trait window definition(W)(), exact(win), dp); } shift (trait::window::definition::unique, W& win, mln dpsite(W)& dp) { mlc is(mln trait window size(W), trait::window::size::fixed)::check(); } 7 / 19 Christopher Chedeau
  • 8. Property Based Dispatch in Functional Languages Lisp Implementation Introduction Olena Properties Lisp Implementation Other Languages (defmethod shift ( (defmethod shift ( Conclusion (win window) (win window) (dp dpsite)) (dp dpsite)) ; Specialization (1) ; Specialization (2) ) ) 8 / 19 Christopher Chedeau
  • 9. Property Based Dispatch in Functional Languages Lisp Implementation Introduction Olena Properties Lisp (defalgo shift ( (defalgo shift ( Implementation (win (win Other Languages Conclusion :properties ( :properties ( :definition :unique :definition :multiple) :size :fixed) window) window) (dp dpsite)) (dp dpsite)) ; Specialization (2) ; Specialization (1) ) ) 9 / 19 Christopher Chedeau
  • 10. Property Based Dispatch in Functional Languages Implementation Overview Introduction Olena Properties Lisp Implementation Other Languages Conclusion 10 / 19 Christopher Chedeau
  • 11. Property Based Dispatch in Functional Languages Fibonacci Introduction Olena Properties (defalgo fibo ((n Lisp (lambda (n) (< n 2)))) Implementation n) Other Languages Conclusion 11 / 19 Christopher Chedeau
  • 12. Property Based Dispatch in Functional Languages Fibonacci Introduction Olena Properties (defalgo fibo ((n Lisp (lambda (n) (< n 2)))) Implementation n) Other Languages Conclusion (defun <2 (n) (< n 2)) (defalgo fibo ((n #’<2)) n) 11 / 19 Christopher Chedeau
  • 13. Property Based Dispatch in Functional Languages Fibonacci Introduction Olena Properties (defalgo fibo ((n (defun is (a) Lisp (lambda (n) (< n 2)))) (lambda (b) Implementation n) (eq a b))) Other Languages Conclusion (defalgo fibo ((n (is 0))) (defun <2 (n) (< n 2)) 0) (defalgo fibo ((n #’<2)) (defalgo fibo ((n (is 1))) n) 1) 11 / 19 Christopher Chedeau
  • 14. Property Based Dispatch in Functional Languages Fibonacci Introduction Olena Properties (defalgo fibo ((n (defun is (a) Lisp (lambda (n) (< n 2)))) (lambda (b) Implementation n) (eq a b))) Other Languages Conclusion (defalgo fibo ((n (is 0))) (defun <2 (n) (< n 2)) 0) (defalgo fibo ((n #’<2)) (defalgo fibo ((n (is 1))) n) 1) (defalgo fibo (n) (+ (fibo (− n 2)) (fibo (− n 1)))) 11 / 19 Christopher Chedeau
  • 15. Property Based Dispatch in Functional Languages Javascript Full Dispatch Introduction Olena Properties Lisp Implementation fibo = FullDispatch() Other Languages Conclusion fibo.add [(n) −> n < 2], (n) −> n fibo.add [null], (n) −> fibo(n − 1) + fibo(n − 2) 12 / 19 Christopher Chedeau
  • 16. Property Based Dispatch in Functional Languages Python Decorators Introduction Olena Properties Lisp Implementation @dispatch(inside(0, 1)) Other Languages def fibo(n): Conclusion return n @dispatch(int) def fibo(n): return fibo(n − 1) + fibo(n − 2) 13 / 19 Christopher Chedeau
  • 17. Property Based Dispatch in Functional Languages Haskell Pattern Matching Introduction Olena Properties Lisp Implementation Other Languages Conclusion fibo 0 = 0 fibo 1 = 1 fibo n = fibo (n − 1) + fibo (n − 2) 14 / 19 Christopher Chedeau
  • 18. Property Based Dispatch in Functional Languages MOP Introduction Olena Properties Lisp Implementation (defmethod fibo (n) Other Languages (+ (fibo (− n 1)) (fibo (− n 2)))) Conclusion (defmethod fibo ((n (eql 1))) n) (defmethod fibo ((n (eql 0))) n) 15 / 19 Christopher Chedeau
  • 19. Property Based Dispatch in Functional Languages Filtered Dispatch Introduction Olena Properties (defun state (n) Lisp Implementation (if (< n 2) Other Languages ’terminal Conclusion ’general)) (defmethod fibo :filter :state ((n (eql ’terminal))) n) (defmethod factorial :filter :state ((n (eql ’general))) (+ (fibo (− n 1)) (fibo (− n 2)))) 16 / 19 Christopher Chedeau
  • 20. Property Based Dispatch in Functional Languages Multimethod.js Introduction Olena Properties Lisp fibo = multimethod() Implementation .dispatch((n) −> if n < 2 Other Languages ’terminal’ Conclusion else ’general’) .when(’terminal’, (n) −> n) .when(’general’, (n) −> fibo(n − 1) + fibo(n − 2)) 17 / 19 Christopher Chedeau
  • 21. Property Based Dispatch in Functional Languages Conclusion Introduction Olena Properties Lisp Implementation Other Languages Conclusion Conclusion 18 / 19 Christopher Chedeau
  • 22. Property Based Dispatch in Functional Languages Questions ? Introduction Olena Properties Lisp Implementation Other Languages Conclusion 19 / 19 Christopher Chedeau