Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Climb - Property-based dispatch in functional l...
Search
vjeux
April 05, 2012
8.7k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Climb - Property-based dispatch in functional languages
vjeux
April 05, 2012
More Decks by vjeux
See All by vjeux
React Rally: Animated -- React Performance Toolbox
vjeux
84
91k
React: CSS in JS - React France Meetup
vjeux
33
12k
React: CSS in JS
vjeux
657
1.5M
OSCON - React Architecture
vjeux
111
45k
Why does React scale? - JSConf 2014
vjeux
52
2M
Image Layout Algorithms - HTML5 Dev Conf
vjeux
13
860k
React Presentation
vjeux
7
14k
Image Layout Algorithms
vjeux
5
820
Generic Image Processing With Climb – 5th ELS
vjeux
1
6k
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
A Soul's Torment
seathinner
6
2.9k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
250
Ruling the World: When Life Gets Gamed
codingconduct
0
250
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
580
Producing Creativity
orderedlist
PRO
348
40k
Transcript
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Property Based Dispatch in Functional Languages Christopher Chedeau LRDE Laboratoire de Recherche et D´ eveloppement d’EPITA January 18, 2012 http://lrde.epita.fr/ 1 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Introduction Olena Properties Lisp Implementation Other Languages Conclusion 2 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Olena Properties Type Name Values image dimension any, one d, two d, three d 3 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Shift Algorithm 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 Introduction Olena Properties Lisp
Implementation Other Languages Conclusion C++ Implementation shift(Window<W>& win, mln dpsite(W)& dp) { // Dispatch on definition property shift (mln trait window definition(W)(), exact(win), dp); } 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 Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Shift Algorithm definition any unique multiple varying Specialization (1) Ö Ö Ö Specialization (2) Ö Ö Ö size any fixed Specialization (1) Ö Specialization (2) 6 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion C++ Implementation shift(Window<W>& win, mln dpsite(W)& dp) { mlc is not(mln trait window definition(W), trait::window::definition::any)::check(); mlc is not(mln trait window definition(W), trait::window::definition::varying)::check(); 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 Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Lisp Implementation (defmethod shift ( (win window) (dp dpsite)) ; Specialization (1) ) (defmethod shift ( (win window) (dp dpsite)) ; Specialization (2) ) 8 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Lisp Implementation (defalgo shift ( (win :properties ( :definition :unique :size :fixed) window) (dp dpsite)) ; Specialization (1) ) (defalgo shift ( (win :properties ( :definition :multiple) window) (dp dpsite)) ; Specialization (2) ) 9 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Implementation Overview 10 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Fibonacci (defalgo fibo ((n (lambda (n) (< n 2)))) n) 11 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Fibonacci (defalgo fibo ((n (lambda (n) (< n 2)))) n) (defun <2 (n) (< n 2)) (defalgo fibo ((n #’<2)) n) 11 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Fibonacci (defalgo fibo ((n (lambda (n) (< n 2)))) n) (defun <2 (n) (< n 2)) (defalgo fibo ((n #’<2)) n) (defun is (a) (lambda (b) (eq a b))) (defalgo fibo ((n (is 0))) 0) (defalgo fibo ((n (is 1))) 1) 11 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Fibonacci (defalgo fibo ((n (lambda (n) (< n 2)))) n) (defun <2 (n) (< n 2)) (defalgo fibo ((n #’<2)) n) (defun is (a) (lambda (b) (eq a b))) (defalgo fibo ((n (is 0))) 0) (defalgo fibo ((n (is 1))) 1) (defalgo fibo (n) (+ (fibo (− n 2)) (fibo (− n 1)))) 11 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Javascript Full Dispatch fibo = FullDispatch() 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 Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Python Decorators @dispatch(inside(0, 1)) def fibo(n): return n @dispatch(int) def fibo(n): return fibo(n − 1) + fibo(n − 2) 13 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Haskell Pattern Matching fibo 0 = 0 fibo 1 = 1 fibo n = fibo (n − 1) + fibo (n − 2) 14 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion MOP (defmethod fibo (n) (+ (fibo (− n 1)) (fibo (− n 2)))) (defmethod fibo ((n (eql 1))) n) (defmethod fibo ((n (eql 0))) n) 15 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Filtered Dispatch (defun state (n) (if (< n 2) ’terminal ’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 Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Multimethod.js fibo = multimethod() .dispatch((n) −> if n < 2 ’terminal’ 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 Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Conclusion Conclusion 18 / 19 Christopher Chedeau
Property Based Dispatch in Functional Languages Introduction Olena Properties Lisp
Implementation Other Languages Conclusion Questions ? 19 / 19 Christopher Chedeau