SlideShare a Scribd company logo
1 of 33
Download to read offline
(S)implicitly
Foundation and Applications of Implicit
Function Types
Martin Odersky, Olivier Blanvillain, Fenyun Liu,
Aggelos Biboudis, Heather Miller, Sandro Stucki
POPL 2018
Con-text
what comes with the text,
but is not in the text
Context is all around us
• the current configuration
• the current scope
• the meaning of “<” on this type
• the user on behalf of which the
operation is performed
• the security level in effect
• …
• globals
rigid if immutable,
unsafe if mutable
• monkey patching
• dependency injection
(e.g. Spring, Guice)
Traditional ways to express context
“Parameterize all the things”
The Functional Way
- no side effects
- type safe
- fine-grained control
Functional is Good
- sea of parameters
- most of which hardly ever change
- repetitive, boring, prone to mistakes
But sometimes it’s too much of a
good thing …
If passing a lot of parameters gets tedious,
leave some of them implicit.
A more direct approach
If passing a lot of parameters gets tedious,
leave some of them implicit.
“Trade types for terms”: We provide the type and
have the compiler synthesize a matching term.
A more direct approach
• If you do not give an argument to an implicit parameter,
one will be provided for you.
• Eligible are all implicit values that are visible at the
point of call.
• If there are more than one eligible candidate, the most
specific one is chosen.
• If there’s no unique most specific candidate, an
ambiguity error Is reported.
Ground Rules
Implicit parameters can
• prove theorems
• establish context
• set configurations
• inject dependencies
• model capabilities
• implement type classes
Use Cases
Implicits are Ubiquitous
Handling Context
Example*: conference management system.
Reviewers should only see (directly or indirectly) the scores
of papers where they have no conflict with an author.
*Suggested by Nadia Polikarpova.
Handling Context
Example: conference management system.
Context is usually stable, can change at specific points.
Can we do better?
Having to write
a couple of times does not look so bad.
But in the new Scala compiler dotc there are > 2600
occurrences of the parameter
Would it not be nice to get rid of them?
Implicit Function Types
Let’s massage the definition of viewRankings a bit:
What is its type?
So far: Viewers => List[Paper]
From now on: implicit Viewers => List[Paper]
Two Rules for Typing
1. Implicit functions get implicit arguments just like implicit
methods. Given:
f expands to f(a).
2. Implicit functions get created on demand. If the
expected type of b is implicit A => B, then
b expands to implicit (_: A) => b
Using Implicit Function Types
Assume:
Then reformulate:
“Trade types for
parameters”
Trade Types for Parameters
• By specifying a type of an expression E, we can provide
in a very general way a context for E.
• Types can be declared directly, or be inferred with local
type inference.
A Formalization
Bidirectional typing rules:
Γ ⊢ t :▷ T (Synthesis)
Γ ⊢ t ◁: T (Checking)
SI Typing Rules: Functions
SI Typing Rules: Variables
SI Typing Rules: Let
SI Typing Rules: Everything
Translation to System F
• The reader monad also allows abstracting context into
a type
• Implicit functions are more lightweight, since they don’t
force you into monadic style.
• They also compose better. For instance:
val a: implicit A => implicit B => R = ???
val b: implicit B => implicit A => R = a
• In the end, Monads are about sequencing, they are
overkill for passing context.
Comparison with the Reader Monad
• Builder pattern
• Tagless interpreters
• Free structures (all of them in the paper)
• Algebraic effects
(Brachthäuser, Schuster, Scala Symp. 2017)
Other Applications
Neat way to define structure-building DSLs, like this:
Natively supported in Groovy and in Kotlin via “receiver
functions”.
An Encore: The Builder Pattern
Scala Implementation
Expansion
• Implicit parameters in Haskell (Lewis et al, 2000)
• Modular implicits in OCaml (White, Bour, Yallop, 2015)
• Agda’s implicit instances (Devriese and Piessens, 2011)
• Implicit Calculus (Olivera, Schrjvers, Wadler et al., 2012,
2017, Rouvoet 2016)
Related Work
Dotty: Dmitry Petrashko Nicolas Stucki
Guillaume Martres Felix Mulder
Ondrej Lhotak Aggelos Biboudis
Liu Fengyun Vera Salvis
Olivier Blanvillain Enno Runne
Sebastien Douraene … and many others
DOT: Nada Amin Tiark Rompf
Sandro Stucki Samuel Grütter
scalac at Adriaan Moors Seth Tisue
Lightbend: Jason Zaugg Stefan Zeiger
Lukas Rytz
Scala Heather Miller Julien Richard-Foy
Center: Jorge Cantero Olafur Geirsson
Guillaume Massé Martin Duheim
Travis Lee
Credits
Thank You
(S)implicitly
Martin Odersky,
Olivier Blanvillain,
Fenyun Liu,
Aggelos Biboudis,
Heather Miller,
Sandro Stucki
EPFL
How to Abstract Over Context?
- Implicit parameters
(aka type classes)
- synthesize programs based
on types.
- Implicit function types
- make implicits even nicer to use
- have simple foundations

More Related Content

What's hot

Scala: functional programming for the imperative mind
Scala: functional programming for the imperative mindScala: functional programming for the imperative mind
Scala: functional programming for the imperative mindSander Mak (@Sander_Mak)
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationMartin Odersky
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in ScalaPatrick Nicolas
 
Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1Berk Soysal
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Practical type mining in Scala
Practical type mining in ScalaPractical type mining in Scala
Practical type mining in ScalaRose Toomey
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the futureAnsviaLab
 
A Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaTomer Gabel
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scalaStratio
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and ClassesMichael Heron
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaSaleem Ansari
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?Alex Payne
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaKnoldus Inc.
 
Java Tutorial Lab 4
Java Tutorial Lab 4Java Tutorial Lab 4
Java Tutorial Lab 4Berk Soysal
 

What's hot (20)

Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Devoxx
DevoxxDevoxx
Devoxx
 
Scala: functional programming for the imperative mind
Scala: functional programming for the imperative mindScala: functional programming for the imperative mind
Scala: functional programming for the imperative mind
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Scala basic
Scala basicScala basic
Scala basic
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Practical type mining in Scala
Practical type mining in ScalaPractical type mining in Scala
Practical type mining in Scala
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the future
 
A Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in Scala
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In Scala
 
Java Tutorial Lab 4
Java Tutorial Lab 4Java Tutorial Lab 4
Java Tutorial Lab 4
 
Intro to Scala
 Intro to Scala Intro to Scala
Intro to Scala
 

Similar to Simplicitly

GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural PatternsSameh Deabes
 
Clean code quotes - Citações e provocações
Clean code quotes - Citações e provocaçõesClean code quotes - Citações e provocações
Clean code quotes - Citações e provocaçõesAndré de Fontana Ignacio
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallJohn Mulhall
 
Microservices: moving parts around
Microservices: moving parts aroundMicroservices: moving parts around
Microservices: moving parts aroundChris Winters
 
Operational challenges behind Serverless architectures
Operational challenges behind Serverless architecturesOperational challenges behind Serverless architectures
Operational challenges behind Serverless architecturesLaurent Bernaille
 
The secret life of rules in Software Engineering
The secret life of rules in Software EngineeringThe secret life of rules in Software Engineering
The secret life of rules in Software EngineeringJordi Cabot
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_pptagnes_crepet
 
The Big Picture - Integrating Buzzwords
The Big Picture - Integrating BuzzwordsThe Big Picture - Integrating Buzzwords
The Big Picture - Integrating BuzzwordsAlessandro Giorgetti
 
Micro-services Battle Scars
Micro-services Battle ScarsMicro-services Battle Scars
Micro-services Battle ScarsRichard Rodger
 
Spec: a lisp-flavoured type system
Spec: a lisp-flavoured type systemSpec: a lisp-flavoured type system
Spec: a lisp-flavoured type systemSimon Belak
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update referencesandeepji_choudhary
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional ProgrammingAapo Kyrölä
 
The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript Corley S.r.l.
 
Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
Tips for writing a paper
Tips for writing a paperTips for writing a paper
Tips for writing a paperGrace Yang
 
Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented developmentrajmundr
 
History of Object Orientation in OOP.ppt
History of Object Orientation in OOP.pptHistory of Object Orientation in OOP.ppt
History of Object Orientation in OOP.pptathar549116
 

Similar to Simplicitly (20)

GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 
Clean code quotes - Citações e provocações
Clean code quotes - Citações e provocaçõesClean code quotes - Citações e provocações
Clean code quotes - Citações e provocações
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John Mulhall
 
Microservices: moving parts around
Microservices: moving parts aroundMicroservices: moving parts around
Microservices: moving parts around
 
Operational challenges behind Serverless architectures
Operational challenges behind Serverless architecturesOperational challenges behind Serverless architectures
Operational challenges behind Serverless architectures
 
The secret life of rules in Software Engineering
The secret life of rules in Software EngineeringThe secret life of rules in Software Engineering
The secret life of rules in Software Engineering
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_ppt
 
The Big Picture - Integrating Buzzwords
The Big Picture - Integrating BuzzwordsThe Big Picture - Integrating Buzzwords
The Big Picture - Integrating Buzzwords
 
Micro-services Battle Scars
Micro-services Battle ScarsMicro-services Battle Scars
Micro-services Battle Scars
 
Spec: a lisp-flavoured type system
Spec: a lisp-flavoured type systemSpec: a lisp-flavoured type system
Spec: a lisp-flavoured type system
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update reference
 
Service as-a-software
Service as-a-softwareService as-a-software
Service as-a-software
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional Programming
 
The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
Tips for writing a paper
Tips for writing a paperTips for writing a paper
Tips for writing a paper
 
Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented development
 
History of Object Orientation in OOP.ppt
History of Object Orientation in OOP.pptHistory of Object Orientation in OOP.ppt
History of Object Orientation in OOP.ppt
 

More from Martin Odersky

Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and EffectsMartin Odersky
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyMartin Odersky
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are DatabasesMartin Odersky
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleMartin Odersky
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange openingMartin Odersky
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 

More from Martin Odersky (10)

scalar.pdf
scalar.pdfscalar.pdf
scalar.pdf
 
Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and Effects
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in Dotty
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are Databases
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
Flatmap
FlatmapFlatmap
Flatmap
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simple
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange opening
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 

Recently uploaded

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
🐬 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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Simplicitly

  • 1. (S)implicitly Foundation and Applications of Implicit Function Types Martin Odersky, Olivier Blanvillain, Fenyun Liu, Aggelos Biboudis, Heather Miller, Sandro Stucki POPL 2018
  • 2. Con-text what comes with the text, but is not in the text
  • 3. Context is all around us • the current configuration • the current scope • the meaning of “<” on this type • the user on behalf of which the operation is performed • the security level in effect • …
  • 4. • globals rigid if immutable, unsafe if mutable • monkey patching • dependency injection (e.g. Spring, Guice) Traditional ways to express context
  • 5. “Parameterize all the things” The Functional Way
  • 6. - no side effects - type safe - fine-grained control Functional is Good
  • 7. - sea of parameters - most of which hardly ever change - repetitive, boring, prone to mistakes But sometimes it’s too much of a good thing …
  • 8. If passing a lot of parameters gets tedious, leave some of them implicit. A more direct approach
  • 9. If passing a lot of parameters gets tedious, leave some of them implicit. “Trade types for terms”: We provide the type and have the compiler synthesize a matching term. A more direct approach
  • 10. • If you do not give an argument to an implicit parameter, one will be provided for you. • Eligible are all implicit values that are visible at the point of call. • If there are more than one eligible candidate, the most specific one is chosen. • If there’s no unique most specific candidate, an ambiguity error Is reported. Ground Rules
  • 11. Implicit parameters can • prove theorems • establish context • set configurations • inject dependencies • model capabilities • implement type classes Use Cases
  • 13. Handling Context Example*: conference management system. Reviewers should only see (directly or indirectly) the scores of papers where they have no conflict with an author. *Suggested by Nadia Polikarpova.
  • 14. Handling Context Example: conference management system. Context is usually stable, can change at specific points.
  • 15. Can we do better? Having to write a couple of times does not look so bad. But in the new Scala compiler dotc there are > 2600 occurrences of the parameter Would it not be nice to get rid of them?
  • 16. Implicit Function Types Let’s massage the definition of viewRankings a bit: What is its type? So far: Viewers => List[Paper] From now on: implicit Viewers => List[Paper]
  • 17. Two Rules for Typing 1. Implicit functions get implicit arguments just like implicit methods. Given: f expands to f(a). 2. Implicit functions get created on demand. If the expected type of b is implicit A => B, then b expands to implicit (_: A) => b
  • 18. Using Implicit Function Types Assume: Then reformulate: “Trade types for parameters”
  • 19. Trade Types for Parameters • By specifying a type of an expression E, we can provide in a very general way a context for E. • Types can be declared directly, or be inferred with local type inference.
  • 20. A Formalization Bidirectional typing rules: Γ ⊢ t :▷ T (Synthesis) Γ ⊢ t ◁: T (Checking)
  • 21. SI Typing Rules: Functions
  • 22. SI Typing Rules: Variables
  • 24. SI Typing Rules: Everything
  • 26. • The reader monad also allows abstracting context into a type • Implicit functions are more lightweight, since they don’t force you into monadic style. • They also compose better. For instance: val a: implicit A => implicit B => R = ??? val b: implicit B => implicit A => R = a • In the end, Monads are about sequencing, they are overkill for passing context. Comparison with the Reader Monad
  • 27. • Builder pattern • Tagless interpreters • Free structures (all of them in the paper) • Algebraic effects (Brachthäuser, Schuster, Scala Symp. 2017) Other Applications
  • 28. Neat way to define structure-building DSLs, like this: Natively supported in Groovy and in Kotlin via “receiver functions”. An Encore: The Builder Pattern
  • 31. • Implicit parameters in Haskell (Lewis et al, 2000) • Modular implicits in OCaml (White, Bour, Yallop, 2015) • Agda’s implicit instances (Devriese and Piessens, 2011) • Implicit Calculus (Olivera, Schrjvers, Wadler et al., 2012, 2017, Rouvoet 2016) Related Work
  • 32. Dotty: Dmitry Petrashko Nicolas Stucki Guillaume Martres Felix Mulder Ondrej Lhotak Aggelos Biboudis Liu Fengyun Vera Salvis Olivier Blanvillain Enno Runne Sebastien Douraene … and many others DOT: Nada Amin Tiark Rompf Sandro Stucki Samuel Grütter scalac at Adriaan Moors Seth Tisue Lightbend: Jason Zaugg Stefan Zeiger Lukas Rytz Scala Heather Miller Julien Richard-Foy Center: Jorge Cantero Olafur Geirsson Guillaume Massé Martin Duheim Travis Lee Credits Thank You
  • 33. (S)implicitly Martin Odersky, Olivier Blanvillain, Fenyun Liu, Aggelos Biboudis, Heather Miller, Sandro Stucki EPFL How to Abstract Over Context? - Implicit parameters (aka type classes) - synthesize programs based on types. - Implicit function types - make implicits even nicer to use - have simple foundations