SlideShare a Scribd company logo
1 of 41
Download to read offline
What to Leave Implicit
Martin Odersky
Curry On and PLDI
Barcelona, June 2017
Con-textual
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
at runtime (Spring, Guice)
or with macros (MacWire)
• cake pattern
close coupling + recursion
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
Implicits
Types
ObjectsFunctions
Essence of Scala
Synthesis
If there’s one feature
that makes Scala
“Scala”, I would pick
implicits.
• takes you through some common uses of implicits,
and some interesting new ones,
• goes through a set of language changes that will
make implicits even more powerful and safer to use.
This Talk
t
• 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
• are a cousin of implicit parameters.
• If the type A of an expression does not match the
expected type B …
… the compiler tries to find an implicit conversion
method from A to B.
• Same rules as for implicit parameters apply.
Implicit Conversions
• … implicit conversions came first in Scala.
• Original motivation: Provide a way for a class to
implement new interfaces.
• Implicit conversions were at first adopted
enthusiastically, but nowadays are mostly discouraged.
• I will ignore them in the rest of this talk.
Historically …
Implicit parameters can
• prove theorems
• establish context
• set configurations
• inject dependencies
• model capabilities
• implement type classes
Implicit Parameters - Use Cases
Curry Howard isomorphism:
Types = Theorems
Programs = Proofs
C.f. Kennedy & Russo: “Generalized Type Constraints”, OOPSLA 2004
Prove Theorems
Establish Context
Example: conference management system.
Reviewers should only see (directly or indirectly) the
scores of papers where they have no conflict with an
author.
Establish Context
Example: conference management system.
Context is usually stable, can change at specific points.
Configuration &
Dependency Management
are special cases of context passing.
see also: Dick Wall: The parfait pattern
Implement Type Classes
Implement Type Classes
Some changes to implicits foreseen for Scala 3:
1. Stricter distinction between parameters and
conversions
2. Implicit by-name parameters
3. Multiple implicit parameter lists
4. Implicit function types
New Developments
Multiple Implicit Parameter Lists
Problem: Implicit parameters are currently a bit irregular
compared to normal parameters:
• there can be only one implicit parameter section
• and it must come last.
This leads to some awkward workarounds (c.f. Aux
pattern).
Related problem: It’s sometimes confusing when a
parameter is implicit or explicit.
Proposal:
• Allow multiple implicit parameter lists
• Implicit and explicit parameter lists can be mixed freely.
• Explicit application of an implicit parameter must be
marked with a new “magic” method, explicitly.
Multiple Implicit Parameter Lists
Implicit Function Types
Let’s look at the conference management system again
Can we do better?
Having to write
a couple of times does not look so bad.
But in dotc there are > 2600 occurrences of the parameter
Would it not be nice to get rid of them?
Towards a solution
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
Revised Example
Assume:
Then reformulate:
Efficiency
Implicit function result types can be optimized
Instead of creating a closure like this:
we can simply create a curried function like this:
This brings the cost of implicit functions down to simple
implicit parameters.
• The reader monad is a somewhat popular method to
pass context.
• Essentially, it wraps the implicit reading in a monad.
• One advantage: The reading is abstracted in a type.
• But I believe this is shooting sparrows with cannons.
• Monads are about sequencing, they have have nothing
to do with passing context.
The Reader Monad
• allow the same conciseness as the reader monad,
• don’t force you into monadic style with explicit
sequencing,
• are fully composable,
• are more than 7x faster than the reader monad.
Implicit Function Types
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
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
• Implicit parameters in Haskell (Lewis et al, 2000)
• Modular implicits in OCaml (White, Bour, Yallop, 2015)
• Agda’s implicit instances (Devriese and Piessens, 2011)
- very similar to implicit function types.
• Implicit Calculus by (Olivera, Schrjvers, Wadler et al.,
2012, 2017)
- a bit further removed from Scala than SI.
- Foundations of Implicit Function Types (Odersky,
Biboudis, Liu, Blanvillain) EPFL Report 229203, 2017
References
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

More Related Content

What's hot

Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaRahul Jain
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationMartin Odersky
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the futureAnsviaLab
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in ScalaPatrick Nicolas
 
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)
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scalapramode_ce
 
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 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
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scalaStratio
 

What's hot (18)

Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Devoxx
DevoxxDevoxx
Devoxx
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the future
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
 
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 Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
Scala basic
Scala basicScala basic
Scala basic
 
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 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
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
 

Similar to What To Leave Implicit

Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
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
 
Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update referencesandeepji_choudhary
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8Heartin Jacob
 
Spec: a lisp-flavoured type system
Spec: a lisp-flavoured type systemSpec: a lisp-flavoured type system
Spec: a lisp-flavoured type systemSimon Belak
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleChristophe Grand
 
EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl Lyndon White
 
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
 
Functional-style control flow in F#
Functional-style control flow in F#Functional-style control flow in F#
Functional-style control flow in F#LincolnAtkinson
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method OverloadingMichael Heron
 
Functional programming for the Advanced Beginner
Functional programming for the Advanced BeginnerFunctional programming for the Advanced Beginner
Functional programming for the Advanced BeginnerLuis Atencio
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And ComponentsDaniel Fagnan
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and ClassesMichael Heron
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesDr. Syed Hassan Amin
 
CPP16 - Object Design
CPP16 - Object DesignCPP16 - Object Design
CPP16 - Object DesignMichael Heron
 
Distributed Model Validation with Epsilon
Distributed Model Validation with EpsilonDistributed Model Validation with Epsilon
Distributed Model Validation with EpsilonSina Madani
 

Similar to What To Leave Implicit (20)

Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
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
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update reference
 
CPP19 - Revision
CPP19 - RevisionCPP19 - Revision
CPP19 - Revision
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Spec: a lisp-flavoured type system
Spec: a lisp-flavoured type systemSpec: a lisp-flavoured type system
Spec: a lisp-flavoured type system
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit Hole
 
EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
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
 
Functional-style control flow in F#
Functional-style control flow in F#Functional-style control flow in F#
Functional-style control flow in F#
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
 
Functional programming for the Advanced Beginner
Functional programming for the Advanced BeginnerFunctional programming for the Advanced Beginner
Functional programming for the Advanced Beginner
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And Components
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
2CPP02 - C++ Primer
2CPP02 - C++ Primer2CPP02 - C++ Primer
2CPP02 - C++ Primer
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
 
CPP16 - Object Design
CPP16 - Object DesignCPP16 - Object Design
CPP16 - Object Design
 
Distributed Model Validation with Epsilon
Distributed Model Validation with EpsilonDistributed Model Validation with Epsilon
Distributed Model Validation with Epsilon
 

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
 
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
 

More from Martin Odersky (7)

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
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are Databases
 
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
 

Recently uploaded

Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksJinanKordab
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Clinic
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Flutter Agency
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIInflectra
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypseTomasz Kowalczewski
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Eraconfluent
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Maxim Salnikov
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024MulesoftMunichMeetup
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNeo4j
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdftimtebeek1
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit MilanNeo4j
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletAndrea Goulet
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfkalichargn70th171
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConNatan Silnitsky
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...drm1699
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Conceptsthomashtkim
 

Recently uploaded (20)

Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...
Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...
Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Concepts
 

What To Leave Implicit

  • 1. What to Leave Implicit Martin Odersky Curry On and PLDI Barcelona, June 2017
  • 2. Con-textual 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 at runtime (Spring, Guice) or with macros (MacWire) • cake pattern close coupling + recursion 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. Implicits Types ObjectsFunctions Essence of Scala Synthesis If there’s one feature that makes Scala “Scala”, I would pick implicits.
  • 10. • takes you through some common uses of implicits, and some interesting new ones, • goes through a set of language changes that will make implicits even more powerful and safer to use. This Talk t
  • 11. • 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
  • 12. • are a cousin of implicit parameters. • If the type A of an expression does not match the expected type B … … the compiler tries to find an implicit conversion method from A to B. • Same rules as for implicit parameters apply. Implicit Conversions
  • 13. • … implicit conversions came first in Scala. • Original motivation: Provide a way for a class to implement new interfaces. • Implicit conversions were at first adopted enthusiastically, but nowadays are mostly discouraged. • I will ignore them in the rest of this talk. Historically …
  • 14. Implicit parameters can • prove theorems • establish context • set configurations • inject dependencies • model capabilities • implement type classes Implicit Parameters - Use Cases
  • 15. Curry Howard isomorphism: Types = Theorems Programs = Proofs C.f. Kennedy & Russo: “Generalized Type Constraints”, OOPSLA 2004 Prove Theorems
  • 16. Establish Context Example: conference management system. Reviewers should only see (directly or indirectly) the scores of papers where they have no conflict with an author.
  • 17. Establish Context Example: conference management system. Context is usually stable, can change at specific points.
  • 18. Configuration & Dependency Management are special cases of context passing. see also: Dick Wall: The parfait pattern
  • 21. Some changes to implicits foreseen for Scala 3: 1. Stricter distinction between parameters and conversions 2. Implicit by-name parameters 3. Multiple implicit parameter lists 4. Implicit function types New Developments
  • 22. Multiple Implicit Parameter Lists Problem: Implicit parameters are currently a bit irregular compared to normal parameters: • there can be only one implicit parameter section • and it must come last. This leads to some awkward workarounds (c.f. Aux pattern). Related problem: It’s sometimes confusing when a parameter is implicit or explicit.
  • 23. Proposal: • Allow multiple implicit parameter lists • Implicit and explicit parameter lists can be mixed freely. • Explicit application of an implicit parameter must be marked with a new “magic” method, explicitly. Multiple Implicit Parameter Lists
  • 24. Implicit Function Types Let’s look at the conference management system again
  • 25. Can we do better? Having to write a couple of times does not look so bad. But in dotc there are > 2600 occurrences of the parameter Would it not be nice to get rid of them?
  • 26. Towards a solution 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]
  • 27. 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
  • 29. Efficiency Implicit function result types can be optimized Instead of creating a closure like this: we can simply create a curried function like this: This brings the cost of implicit functions down to simple implicit parameters.
  • 30. • The reader monad is a somewhat popular method to pass context. • Essentially, it wraps the implicit reading in a monad. • One advantage: The reading is abstracted in a type. • But I believe this is shooting sparrows with cannons. • Monads are about sequencing, they have have nothing to do with passing context. The Reader Monad
  • 31. • allow the same conciseness as the reader monad, • don’t force you into monadic style with explicit sequencing, • are fully composable, • are more than 7x faster than the reader monad. Implicit Function Types
  • 32. Neat way to define structure-building DSLs, like this: Natively supported in Groovy and in Kotlin via “receiver functions”. An Encore: The Builder Pattern
  • 34. A Formalization Bidirectional typing rules: Γ ⊢ t :▷ T (Synthesis) Γ ⊢ t ◁: T (Checking)
  • 35. SI Typing Rules: Functions
  • 36. SI Typing Rules: Variables
  • 38. SI Typing Rules: Everything
  • 40. • Implicit parameters in Haskell (Lewis et al, 2000) • Modular implicits in OCaml (White, Bour, Yallop, 2015) • Agda’s implicit instances (Devriese and Piessens, 2011) - very similar to implicit function types. • Implicit Calculus by (Olivera, Schrjvers, Wadler et al., 2012, 2017) - a bit further removed from Scala than SI. - Foundations of Implicit Function Types (Odersky, Biboudis, Liu, Blanvillain) EPFL Report 229203, 2017 References
  • 41. 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