SlideShare a Scribd company logo
1 of 22
Download to read offline
Revisiting
Combinators
Edward Kmett
data LC a
= Var a
| App (LC a) (LC a)
| Lam (LC (Maybe a))
deriving (Functor, Foldable, Traversable)
instance Applicative LC where pure = Var; (<*>) = ap
instance Monad LC where
Var a >>= f = f a
App l r >>= f = App (l >>= f) (r >>= f)
Lam k >>= f = Lam $ k >>= case
Nothing -> pure Nothing
Just a -> Just <$> f a
lam :: Eq a => a -> LC a -> LC a
lam v b = Lam $ bind v <$> b where
bind v u = u <$ guard (u /= v)
A Toy Lambda Calculus
A combinator is a function that has no free
variables.
What is a Combinator?
• Moses Shönfinkel (Моисей Исаевич Шейнфинкель), “Über die Bausteine der
mathematischen Logik” 1924
• Haskell Curry, “Grundlagen der Kombinatorischen Logik” 1930
• David Turner, “Another Algorithm for Bracket Abstraction” 1979
• Smullyan “To Mock a Mockingbird” 1985
• Sabine Broda and Lúis Damas “Bracket abstraction in the combinator system Cl(K)”
1987(?)
Introducing Combinators
data CL a = V a | A (CL a) (CL a) | S | K | I | B | C
deriving (Functor, Foldable, Traversable)
instance Applicative CL where pure = V; (<*>) = ap
instance Monad CL where
V a >>= f = f a
A l r >>= f = A (l >>= f) (r >>= f)
S >>= _ = S
K >>= _ = K
I >>= _ = I
B >>= _ = B
C >>= _ = C
A Toy Combinatory Logic
S x y z = (x z) (y z) -- (<*>)
K x y = x -- const
I x = x -- id
B x y z = x (y z) -- (.)
C x y z = x z y -- flip
Y f = f (Y f) = let x = f x in x -- fix
A Field Guide
infixl 1 %
(%) = A
compile :: LC a -> CL a
compile (Var a) = V a
compile (App l r) = compile l % compile r
compile (Lam b) = compileLam b
compileLam :: LC (Maybe a) -> CL a
compileLam (Var Nothing)) = I
compileLam (Var (Just y)) = K % V y
compileLam (Ap l r) = case (sequence l, sequence r) of
(Nothing, Nothing) -> S % compileLam l % compileLam r
(Nothing, Just r') -> C % compileLam l % compile r
(Just l', Nothing) -> B % compile l' % compileLam r
(Just l', Just r') -> K % (compile l' % compile r')
compileLam (Lam b) = join $ compileLam $ dist $ compileLam b where
dist :: C (Maybe a) -> L (Maybe (C a))
dist (A l r) = App (dist l) (dist r)
dist xs = Var (sequence xs)
Abstraction Elimination
Play with this at http://pointfree.io/ or with @pl on lambdabot
a la Shönfinkel
• John Hughes, “Super Combinators: A New Implementation Method for Applicative
Languages” 1982
• Lennart Augustsson, “A compiler for Lazy ML” 1984
• Simon Peyton Jones “Implementing lazy functional languages on stock hardware: the
Spineless Tagless G-machine” 1992
• Simon Marlow, Alexey Rodriguez Yakushev and Simon Peyton Jones “Faster laziness
using dynamic pointer tagging” 2007
Supercombinators
jmp %eax
Unknown Thunk Evaluation
Every Thunk in GHC is a SPECTRE v2 Vulnerability
• Small evaluator that immediately recovers
coherence between instructions.
• Scales with the product of the SIMD-width and # of
cores, rather than one or the other
• This bypasses the spectre issues.
• This generalizes to GPU compute shading
SPMD-on-SIMD Evaluation
Why are combinator terms
bigger?
• S x y z = (x z) (y z) — application with environment
• K x y = x — ignores environment
• I x — uses environment
• These all work “one variable at a time”
We need to be able to build and manipulate ‘partial’ environments in sublinear time.
Some references:
• Abadi, Cardelli, Curien, Lévy “Explicit Substitutions” 1990
• Lescanne, “From λσ to λν a journey through calculi of explicit substitutions” 1994
• Mazzoli, “A Well-Typed Suspension Calculus” 2017
Sketching an “improved”
abstraction elimination algorithm
fst (a,b) ~> a
snd (a,b) ~> b
Evaluation by Collection
• John Hughes, “The design and implementation of programming languages” 1983
• Philip Wadler, “Fixing some space leaks with a garbage collector” 1987
• Christina von Dorrien, “Stingy Evaluation” 1989
Some extra stingy combinator evaluation rules:
A (A K x) _ -> Just x -- def K
A I x -> Just x -- def I
A S K -> Just K_ -- Hudak 1
A S K_ -> Just I -- Hudak 2
A S k@(A K (A K _)) -> Just k -- Hudak 3
A (A S (A K x)) I -> Just x -- Hudak 4, Turner p35 2
A Y k@(A K _) -> Just k -- Hudak 9
(Be careful, not all of Hudak’s rules are stingy!)
• Paul Hudak and David Kranz, “A Combinator-based Compiler for a Functional
Language” 1984
One Bit Reference Counting
S
x
y
z
x yz z
(<*>)
W.R. Stoye, T.J.W. Clarke and A.C. Norman “Some Practical Methods for Rapid Combinator Reduction”
1984
One Bit Reference Counting
C
x
y
z
x
y
z
flip
One Bit Reference Counting
B
x
y
z
x
y z
(.)
K
x
y x
const
Extra reductions that require “uniqueness” to be stingy:
A (A (A C f) x) y -> Just $ A (A f y) x
A (A (A B f) g) x -> Just $ A f (A g x)
A (A S (A K x)) (A K y) -> Just $ A K (A x y) -- Hudak 5, Turner p35 1
A (A S (A K x)) y -> Just $ A (A B x) y -- Turner p35 3
A (A S x) (A K y) -> Just $ A (A C x) y -- Turner p35 4
fst p = p (xy.x)
pair x y z = z x y
snd p = p (xy.y)
fst = CIK
snd = CI(KI)
pair = BC(CI)
Can we reduce fst (x, y) ~> x by stingy evaluation
without special casing Wadler’s rules?
• None of the S,B,C,K,I… rules introduce new cycles
on the heap except Y.
• Hash-consing!
• Eiichi Goto “Monocopy and associative
algorithms in extended Lisp” 1974
• Eelco Dolstra, “Maximal Laziness” 2008
Optionally Acyclic Heaps
• Compilers for dependently typed languages are slow. Hash consign is usually bolted in as
an afterthought. I’d like an efficient default evaluator that automatically memoizes and
addresses unification and substitution concerns.
• Daniel Dougherty “Higher-order unification via combinators” 1993
Why I Care?

More Related Content

What's hot

Kotlin Coroutines Reloaded
Kotlin Coroutines ReloadedKotlin Coroutines Reloaded
Kotlin Coroutines ReloadedRoman Elizarov
 
Image Processing on Delta Lake
Image Processing on Delta LakeImage Processing on Delta Lake
Image Processing on Delta LakeDatabricks
 
Practical learnings from running thousands of Flink jobs
Practical learnings from running thousands of Flink jobsPractical learnings from running thousands of Flink jobs
Practical learnings from running thousands of Flink jobsFlink Forward
 
RxNetty vs Tomcat Performance Results
RxNetty vs Tomcat Performance ResultsRxNetty vs Tomcat Performance Results
RxNetty vs Tomcat Performance ResultsBrendan Gregg
 
Dynamic Rule-based Real-time Market Data Alerts
Dynamic Rule-based Real-time Market Data AlertsDynamic Rule-based Real-time Market Data Alerts
Dynamic Rule-based Real-time Market Data AlertsFlink Forward
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Sunghyouk Bae
 
Stateful stream processing with Apache Flink
Stateful stream processing with Apache FlinkStateful stream processing with Apache Flink
Stateful stream processing with Apache FlinkKnoldus Inc.
 
Introduction To Catalyst - Part 1
Introduction To Catalyst - Part 1Introduction To Catalyst - Part 1
Introduction To Catalyst - Part 1Dan Dascalescu
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudAmazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudNoritaka Sekiyama
 
Debugging node in prod
Debugging node in prodDebugging node in prod
Debugging node in prodYunong Xiao
 
Logstage - zero-cost-tructured-logging
Logstage - zero-cost-tructured-loggingLogstage - zero-cost-tructured-logging
Logstage - zero-cost-tructured-logging7mind
 
Developer’s guide to contributing code to Kafka with Mickael Maison and Tom B...
Developer’s guide to contributing code to Kafka with Mickael Maison and Tom B...Developer’s guide to contributing code to Kafka with Mickael Maison and Tom B...
Developer’s guide to contributing code to Kafka with Mickael Maison and Tom B...HostedbyConfluent
 
Vectorized Query Execution in Apache Spark at Facebook
Vectorized Query Execution in Apache Spark at FacebookVectorized Query Execution in Apache Spark at Facebook
Vectorized Query Execution in Apache Spark at FacebookDatabricks
 
Scylla Summit 2022: Scylla 5.0 New Features, Part 1
Scylla Summit 2022: Scylla 5.0 New Features, Part 1Scylla Summit 2022: Scylla 5.0 New Features, Part 1
Scylla Summit 2022: Scylla 5.0 New Features, Part 1ScyllaDB
 
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...Databricks
 
PostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / ShardingPostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / ShardingAmir Reza Hashemi
 
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, ConfluentTemporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, ConfluentHostedbyConfluent
 
Apache Kafka in the Airline, Aviation and Travel Industry
Apache Kafka in the Airline, Aviation and Travel IndustryApache Kafka in the Airline, Aviation and Travel Industry
Apache Kafka in the Airline, Aviation and Travel IndustryKai Wähner
 

What's hot (20)

Kotlin Coroutines Reloaded
Kotlin Coroutines ReloadedKotlin Coroutines Reloaded
Kotlin Coroutines Reloaded
 
Image Processing on Delta Lake
Image Processing on Delta LakeImage Processing on Delta Lake
Image Processing on Delta Lake
 
Practical learnings from running thousands of Flink jobs
Practical learnings from running thousands of Flink jobsPractical learnings from running thousands of Flink jobs
Practical learnings from running thousands of Flink jobs
 
RxNetty vs Tomcat Performance Results
RxNetty vs Tomcat Performance ResultsRxNetty vs Tomcat Performance Results
RxNetty vs Tomcat Performance Results
 
Dynamic Rule-based Real-time Market Data Alerts
Dynamic Rule-based Real-time Market Data AlertsDynamic Rule-based Real-time Market Data Alerts
Dynamic Rule-based Real-time Market Data Alerts
 
Golang Channels
Golang ChannelsGolang Channels
Golang Channels
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017
 
Stateful stream processing with Apache Flink
Stateful stream processing with Apache FlinkStateful stream processing with Apache Flink
Stateful stream processing with Apache Flink
 
Introduction To Catalyst - Part 1
Introduction To Catalyst - Part 1Introduction To Catalyst - Part 1
Introduction To Catalyst - Part 1
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudAmazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
 
Debugging node in prod
Debugging node in prodDebugging node in prod
Debugging node in prod
 
Logstage - zero-cost-tructured-logging
Logstage - zero-cost-tructured-loggingLogstage - zero-cost-tructured-logging
Logstage - zero-cost-tructured-logging
 
Developer’s guide to contributing code to Kafka with Mickael Maison and Tom B...
Developer’s guide to contributing code to Kafka with Mickael Maison and Tom B...Developer’s guide to contributing code to Kafka with Mickael Maison and Tom B...
Developer’s guide to contributing code to Kafka with Mickael Maison and Tom B...
 
Vectorized Query Execution in Apache Spark at Facebook
Vectorized Query Execution in Apache Spark at FacebookVectorized Query Execution in Apache Spark at Facebook
Vectorized Query Execution in Apache Spark at Facebook
 
Scylla Summit 2022: Scylla 5.0 New Features, Part 1
Scylla Summit 2022: Scylla 5.0 New Features, Part 1Scylla Summit 2022: Scylla 5.0 New Features, Part 1
Scylla Summit 2022: Scylla 5.0 New Features, Part 1
 
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...
 
PostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / ShardingPostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / Sharding
 
Rust Primer
Rust PrimerRust Primer
Rust Primer
 
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, ConfluentTemporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
 
Apache Kafka in the Airline, Aviation and Travel Industry
Apache Kafka in the Airline, Aviation and Travel IndustryApache Kafka in the Airline, Aviation and Travel Industry
Apache Kafka in the Airline, Aviation and Travel Industry
 

Similar to Revisiting Combinators

Optimization introduction
Optimization introductionOptimization introduction
Optimization introductionhelalmohammad2
 
Convergence Criteria
Convergence CriteriaConvergence Criteria
Convergence CriteriaTarun Gehlot
 
Relaxation methods for the matrix exponential on large networks
Relaxation methods for the matrix exponential on large networksRelaxation methods for the matrix exponential on large networks
Relaxation methods for the matrix exponential on large networksDavid Gleich
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
Strong functional programming
Strong functional programmingStrong functional programming
Strong functional programmingEric Torreborre
 
Good functional programming is good programming
Good functional programming is good programmingGood functional programming is good programming
Good functional programming is good programmingkenbot
 
Planning Under Uncertainty With Markov Decision Processes
Planning Under Uncertainty With Markov Decision ProcessesPlanning Under Uncertainty With Markov Decision Processes
Planning Under Uncertainty With Markov Decision Processesahmad bassiouny
 
Microsoft Word Practice Exercise Set 2
Microsoft Word   Practice Exercise Set 2Microsoft Word   Practice Exercise Set 2
Microsoft Word Practice Exercise Set 2rampan
 
FirstAndSecond.pptx.pdf
FirstAndSecond.pptx.pdfFirstAndSecond.pptx.pdf
FirstAndSecond.pptx.pdfShanmukhSaiR
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Bryan O'Sullivan
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsEelco Visser
 
Introduction to complex networks
Introduction to complex networksIntroduction to complex networks
Introduction to complex networksVincent Traag
 
ML+Hadoop at NYC Predictive Analytics
ML+Hadoop at NYC Predictive AnalyticsML+Hadoop at NYC Predictive Analytics
ML+Hadoop at NYC Predictive AnalyticsErik Bernhardsson
 
Applied Machine Learning For Search Engine Relevance
Applied Machine Learning For Search Engine Relevance Applied Machine Learning For Search Engine Relevance
Applied Machine Learning For Search Engine Relevance charlesmartin14
 
lecture01_lecture01_lecture0001_ceva.pdf
lecture01_lecture01_lecture0001_ceva.pdflecture01_lecture01_lecture0001_ceva.pdf
lecture01_lecture01_lecture0001_ceva.pdfAnaNeacsu5
 
Laplace1 8merged
Laplace1 8mergedLaplace1 8merged
Laplace1 8mergedcohtran
 
ACL2 Backtracking
ACL2 BacktrackingACL2 Backtracking
ACL2 Backtrackingguesta07923
 

Similar to Revisiting Combinators (20)

Optimization introduction
Optimization introductionOptimization introduction
Optimization introduction
 
Convergence Criteria
Convergence CriteriaConvergence Criteria
Convergence Criteria
 
Relaxation methods for the matrix exponential on large networks
Relaxation methods for the matrix exponential on large networksRelaxation methods for the matrix exponential on large networks
Relaxation methods for the matrix exponential on large networks
 
Monadologie
MonadologieMonadologie
Monadologie
 
Strong functional programming
Strong functional programmingStrong functional programming
Strong functional programming
 
Matrix calculus
Matrix calculusMatrix calculus
Matrix calculus
 
Good functional programming is good programming
Good functional programming is good programmingGood functional programming is good programming
Good functional programming is good programming
 
Planning Under Uncertainty With Markov Decision Processes
Planning Under Uncertainty With Markov Decision ProcessesPlanning Under Uncertainty With Markov Decision Processes
Planning Under Uncertainty With Markov Decision Processes
 
Microsoft Word Practice Exercise Set 2
Microsoft Word   Practice Exercise Set 2Microsoft Word   Practice Exercise Set 2
Microsoft Word Practice Exercise Set 2
 
FirstAndSecond.pptx.pdf
FirstAndSecond.pptx.pdfFirstAndSecond.pptx.pdf
FirstAndSecond.pptx.pdf
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
Introduction to complex networks
Introduction to complex networksIntroduction to complex networks
Introduction to complex networks
 
PARSING.ppt
PARSING.pptPARSING.ppt
PARSING.ppt
 
ML+Hadoop at NYC Predictive Analytics
ML+Hadoop at NYC Predictive AnalyticsML+Hadoop at NYC Predictive Analytics
ML+Hadoop at NYC Predictive Analytics
 
Applied Machine Learning For Search Engine Relevance
Applied Machine Learning For Search Engine Relevance Applied Machine Learning For Search Engine Relevance
Applied Machine Learning For Search Engine Relevance
 
lecture01_lecture01_lecture0001_ceva.pdf
lecture01_lecture01_lecture0001_ceva.pdflecture01_lecture01_lecture0001_ceva.pdf
lecture01_lecture01_lecture0001_ceva.pdf
 
QMC: Operator Splitting Workshop, A New (More Intuitive?) Interpretation of I...
QMC: Operator Splitting Workshop, A New (More Intuitive?) Interpretation of I...QMC: Operator Splitting Workshop, A New (More Intuitive?) Interpretation of I...
QMC: Operator Splitting Workshop, A New (More Intuitive?) Interpretation of I...
 
Laplace1 8merged
Laplace1 8mergedLaplace1 8merged
Laplace1 8merged
 
ACL2 Backtracking
ACL2 BacktrackingACL2 Backtracking
ACL2 Backtracking
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Revisiting Combinators

  • 2. data LC a = Var a | App (LC a) (LC a) | Lam (LC (Maybe a)) deriving (Functor, Foldable, Traversable) instance Applicative LC where pure = Var; (<*>) = ap instance Monad LC where Var a >>= f = f a App l r >>= f = App (l >>= f) (r >>= f) Lam k >>= f = Lam $ k >>= case Nothing -> pure Nothing Just a -> Just <$> f a lam :: Eq a => a -> LC a -> LC a lam v b = Lam $ bind v <$> b where bind v u = u <$ guard (u /= v) A Toy Lambda Calculus
  • 3. A combinator is a function that has no free variables. What is a Combinator?
  • 4. • Moses Shönfinkel (Моисей Исаевич Шейнфинкель), “Über die Bausteine der mathematischen Logik” 1924 • Haskell Curry, “Grundlagen der Kombinatorischen Logik” 1930 • David Turner, “Another Algorithm for Bracket Abstraction” 1979 • Smullyan “To Mock a Mockingbird” 1985 • Sabine Broda and Lúis Damas “Bracket abstraction in the combinator system Cl(K)” 1987(?) Introducing Combinators
  • 5. data CL a = V a | A (CL a) (CL a) | S | K | I | B | C deriving (Functor, Foldable, Traversable) instance Applicative CL where pure = V; (<*>) = ap instance Monad CL where V a >>= f = f a A l r >>= f = A (l >>= f) (r >>= f) S >>= _ = S K >>= _ = K I >>= _ = I B >>= _ = B C >>= _ = C A Toy Combinatory Logic
  • 6. S x y z = (x z) (y z) -- (<*>) K x y = x -- const I x = x -- id B x y z = x (y z) -- (.) C x y z = x z y -- flip Y f = f (Y f) = let x = f x in x -- fix A Field Guide
  • 7. infixl 1 % (%) = A compile :: LC a -> CL a compile (Var a) = V a compile (App l r) = compile l % compile r compile (Lam b) = compileLam b compileLam :: LC (Maybe a) -> CL a compileLam (Var Nothing)) = I compileLam (Var (Just y)) = K % V y compileLam (Ap l r) = case (sequence l, sequence r) of (Nothing, Nothing) -> S % compileLam l % compileLam r (Nothing, Just r') -> C % compileLam l % compile r (Just l', Nothing) -> B % compile l' % compileLam r (Just l', Just r') -> K % (compile l' % compile r') compileLam (Lam b) = join $ compileLam $ dist $ compileLam b where dist :: C (Maybe a) -> L (Maybe (C a)) dist (A l r) = App (dist l) (dist r) dist xs = Var (sequence xs) Abstraction Elimination Play with this at http://pointfree.io/ or with @pl on lambdabot a la Shönfinkel
  • 8. • John Hughes, “Super Combinators: A New Implementation Method for Applicative Languages” 1982 • Lennart Augustsson, “A compiler for Lazy ML” 1984 • Simon Peyton Jones “Implementing lazy functional languages on stock hardware: the Spineless Tagless G-machine” 1992 • Simon Marlow, Alexey Rodriguez Yakushev and Simon Peyton Jones “Faster laziness using dynamic pointer tagging” 2007 Supercombinators
  • 9. jmp %eax Unknown Thunk Evaluation Every Thunk in GHC is a SPECTRE v2 Vulnerability
  • 10. • Small evaluator that immediately recovers coherence between instructions. • Scales with the product of the SIMD-width and # of cores, rather than one or the other • This bypasses the spectre issues. • This generalizes to GPU compute shading SPMD-on-SIMD Evaluation
  • 11. Why are combinator terms bigger? • S x y z = (x z) (y z) — application with environment • K x y = x — ignores environment • I x — uses environment • These all work “one variable at a time”
  • 12. We need to be able to build and manipulate ‘partial’ environments in sublinear time. Some references: • Abadi, Cardelli, Curien, Lévy “Explicit Substitutions” 1990 • Lescanne, “From λσ to λν a journey through calculi of explicit substitutions” 1994 • Mazzoli, “A Well-Typed Suspension Calculus” 2017 Sketching an “improved” abstraction elimination algorithm
  • 13. fst (a,b) ~> a snd (a,b) ~> b Evaluation by Collection • John Hughes, “The design and implementation of programming languages” 1983 • Philip Wadler, “Fixing some space leaks with a garbage collector” 1987 • Christina von Dorrien, “Stingy Evaluation” 1989
  • 14. Some extra stingy combinator evaluation rules: A (A K x) _ -> Just x -- def K A I x -> Just x -- def I A S K -> Just K_ -- Hudak 1 A S K_ -> Just I -- Hudak 2 A S k@(A K (A K _)) -> Just k -- Hudak 3 A (A S (A K x)) I -> Just x -- Hudak 4, Turner p35 2 A Y k@(A K _) -> Just k -- Hudak 9 (Be careful, not all of Hudak’s rules are stingy!) • Paul Hudak and David Kranz, “A Combinator-based Compiler for a Functional Language” 1984
  • 15. One Bit Reference Counting S x y z x yz z (<*>) W.R. Stoye, T.J.W. Clarke and A.C. Norman “Some Practical Methods for Rapid Combinator Reduction” 1984
  • 16. One Bit Reference Counting C x y z x y z flip
  • 17. One Bit Reference Counting B x y z x y z (.)
  • 19. Extra reductions that require “uniqueness” to be stingy: A (A (A C f) x) y -> Just $ A (A f y) x A (A (A B f) g) x -> Just $ A f (A g x) A (A S (A K x)) (A K y) -> Just $ A K (A x y) -- Hudak 5, Turner p35 1 A (A S (A K x)) y -> Just $ A (A B x) y -- Turner p35 3 A (A S x) (A K y) -> Just $ A (A C x) y -- Turner p35 4
  • 20. fst p = p (xy.x) pair x y z = z x y snd p = p (xy.y) fst = CIK snd = CI(KI) pair = BC(CI) Can we reduce fst (x, y) ~> x by stingy evaluation without special casing Wadler’s rules?
  • 21. • None of the S,B,C,K,I… rules introduce new cycles on the heap except Y. • Hash-consing! • Eiichi Goto “Monocopy and associative algorithms in extended Lisp” 1974 • Eelco Dolstra, “Maximal Laziness” 2008 Optionally Acyclic Heaps
  • 22. • Compilers for dependently typed languages are slow. Hash consign is usually bolted in as an afterthought. I’d like an efficient default evaluator that automatically memoizes and addresses unification and substitution concerns. • Daniel Dougherty “Higher-order unification via combinators” 1993 Why I Care?