SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
What’s new in OCaml 4.02
Xavier Leroy
INRIA Paris-Rocquencourt
OCaml Workshop, 2014-09-05
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 1 / 20
Recent releases
Major release 4.01.0: (Sept. 2013)
More lenient typing of ambiguous record labels and data constructors.
Usability features:
-short-path option to print inferred types more legibly.
A lot of new warnings.
Suggested corrections for misspelt identifiers.
135 bug fixes, 25 feature wishes.
Major release 4.02.0: (Sept. 2014)
A great many new features!
66 bug fixes, 18 feature wishes.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 2 / 20
Unified matching on values and exceptions
A classic programming problem: in let x = a in b, catch exceptions
raised by a but not those raised by b.
Wrong solution: put a try. . . with around let.
let rec readfile ic accu =
try let l = input_line ic in readfile ic (l :: accu)
with End_of_file -> List.rev accu
The try covers the recursive call to readfile and prevents it from being
a tail call.
Option-based encoding: correct but heavy.
let rec readfile ic accu =
match
try Some(input_line ic) with End_of_file -> None
with
| Some l -> readfile ic (l :: accu)
| None -> List.rev accu
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 3 / 20
Unified matching on values and exceptions
(Jeremy Yallop, Alain Frisch)
In OCaml 4.02: the match a with construct is extended to analyse both
the value of a and exceptions raised during a’s evaluation.
let rec readfile ic accu =
match input_line ic with
| "" -> readfile ic accu
| l -> readfile ic (l :: accu)
| exception End_of_file -> List.rev accu
Compilation preserves tail-call optimization for the recursive call. No
allocation of intermediate Some results.
The usual try. . . with construct is a special case:
try ... with Not_found -> 0
≡
match ... with x -> x | exception Not_found -> 0
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 4 / 20
Module aliases
Common practice: bind an existing module to another name.
module A = struct
module M = AnotherModule
...
end
To have short qualified names M.x inside the body of A.
To re-export a module or compilation unit as a submodule of another.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 5 / 20
Module aliases
module A = struct
module M = AnotherModule
...
end
In classic OCaml, this binding is treated like any other definition
module M = module-expr
Typing: the equality A.M = AnotherModule is not recorded, can
cause type errors with applicative functors.
Compilation: accesses A.M.x sometimes go through more indirections
than AnotherModule.x.
Linking: a reference to A.M.x links in the whole of module A, not just
AnotherModule.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 6 / 20
Module aliases in OCaml 4.02
(Jacques Garrigue, Leo White)
In 4.02, module M = AnotherModule is treated specially:
During type-checking: the equality is recorded in the signature of the
enclosing module
A : sig module M = AnotherModule ... end
During compilation: direct accesses to AnotherModule are generated.
During linking: an access A.M.x no longer forces A to be linked in
full, but only AnotherModule.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 7 / 20
Application to libraries
Goal: expose (to users) a library as a single unit L with submodules
L.A, L.B, etc.
Approach 1: single source
Write and compile L as a single source file L.ml.
Problem: does not scale.
Approach 2: packing
Put A, B in distinct source files A.ml, B.ml, separately compiled.
Use ocamlopt -pack -o L.cmx to produce the single unit L.
Problem: L is always linked in full.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 8 / 20
Application to libraries
New approach: use module aliases
Put A, B in distinct source files L_A.ml, L_B.ml, separately compiled.
(Note: the names L_A, L_B must be globally unique.)
Write and compile a wrapper L.ml that re-exports them with short names:
L.ml: module A = L_A
module B = L_B
Build and install an archive L.cmxa containing L_A, L_B, and L.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 9 / 20
Mutability of strings
For historical reasons, the string type of OCaml is mutable in place and
has two broad uses:
To represent text:
let string_of_pair (x,y) = "(" ^ x ^ ", " ^ y ^")"
As I/O buffers:
let read_data ic n =
let buf = String.create n in
let len = Unix.read ic buf 0 n in
String.sub buf 0 len
OCaml programmers are very good at keeping the two uses distinct.
But mistakes happen, and user code can be malicious. . .
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 10 / 20
Pitfalls of mutable strings
Mutating someone else’s string literals: (Lafosec study, ANSSI)
# (Char.escaped ’t’).[1] <- ’n’;;
- : unit = ()
# Char.escaped ’t’;;
- : string = "n"
# String.blit "true " 0 (string_of_bool false) 0 5;;
- : unit = ()
# string_of_bool false;;
- : string = "true "
The disappearing key:
let s = "foo" in
Hashtbl.add tbl s 10;
s.[1] <- ’x’;
Hashtbl.find tbl "foo"
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 11 / 20
Pitfalls of mutable strings
LCF-style theorem proving:
module ProofSystem : sig
type thm
val modusponens: thm -> thm -> thm
val axiom_eqrefl: term -> thm
val axiom_and: formula -> formula -> formula
...
end
By subverting the OCaml type system or using mutability of
strings, it is possible to derive false results even in our LCF
prover, but we restrict ourselves to ‘normal’ functional
programming.
J. Harrison, Handbook of Practical Logic
and Automated Reasoning
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 12 / 20
Towards immutable strings (Damien Doligez)
In 4.02, two base types string (for text) and bytes (≈ byte arrays):
By default, string and bytes are synonymous.
They are incompatible if option -safe-string is given.
In standard library String, functions that mutate strings are given types
involving bytes and marked as deprecated:
string.mli: val set : bytes -> int -> char -> unit
[@@ocaml.deprecated]
A new standard library module Bytes is provided with a full set of
imperative functions operating over bytes, including conversion functions
(with copy):
bytes.mli: val set : bytes -> int -> char -> unit
val of_string: string -> bytes
val to_string: bytes -> string
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 13 / 20
What changes?
In default mode:
All existing code compiles.
Warnings when using String functions that mutate in place.
In -safe-string mode:
Values of type string are immutable.
(Unless unsafe coercions are used.)
I/O code and imperative constructions of strings need to be rewritten
to use type bytes and library functions Bytes.
A plea for developers of libraries: try to port your code to -safe-string
mode and let us know how it worked.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 14 / 20
Other novelties in OCaml 4.02
Language features:
Explicitly generative functors. (Jacques Garrigue)
A language of annotations over OCaml terms.
Annotations are used by the compiler (e.g. to mark deprecated
functions) and by preprocessors. (Alain Frisch)
External preprocessors that rewrite the typed abstract syntax tree
(-ppx option). (Alain Frisch)
Open datatypes, extensible a posteriori with additional constructors.
(Leo White)
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 15 / 20
Other novelties in OCaml 4.02
Performance improvements:
More aggressive constant propagation; dead code elimination;
common subexpression elimination. (Xavier Leroy)
More efficient pattern-matching over strings.
(Benoˆıt Vaugon, Luc Maranget)
More efficient and safer implementation of printf based on GADTs.
(Benoˆıt Vaugon, Gabriel Scherer)
More efficient representation of exceptions without arguments.
(Alain Frisch)
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 16 / 20
Other novelties in OCaml 4.02
Usability:
New toplevel directives to query the environment, e.g.
#show_type list or #show_module String.
(Jacques Garrigue, Alain Frisch)
New port:
AArch64 (ARM in 64-bit mode).
(Xavier Leroy, debugging by Richard Jones)
Source reorganization:
Camlp4 and Labltk were split off the core distribution and now live as
independent projects — one opam install away.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 17 / 20
This release brought to you by. . .
Damien Doligez,
release manager and general wizard.
The core Caml development team: Jacques Garrigue, Alain Frisch, Fabrice
Le Fessant, Xavier Leroy, Gabriel Scherer, Mark Shinwell, Leo White,
Jeremy Yallop
With much appreciated contributions from: Anil Madhavapeddy, Benoˆıt Vaugon,
Daniel B¨unzli, David Allsopp, Hongbo Zhang, Jacques-Henri Jourdan, Jacques-Pascal
Deplaix, John Whitington, Jonathan Protzenko, Jun Furuse, J´er´emie Dimino, Luc
Maranget, Markus Mottl, Maxence Guesdon, Phil Denys, Pierre Chambart, Richard
Jones, Romain Bardou, Stephen Dolan, St´ephane Glondu, Thomas Refis, Vladimir
Brankov, ygrek.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 18 / 20
What’s next?
Bug-fix release 4.02.1.
Language features:
Various experiments in progress; nothing decided yet.
Implementation:
More optimizations, esp. improved inlining (Pierre Chambart).
Ephemerons (Fran¸cois Bobot, Damien Doligez)
GDB support (Mark Shinwell)
Tweaks to support OPAM better.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 19 / 20
In closing. . .
Enjoy OCaml 4.02!
Try to port your code to “safe string” mode: one day it might become the
default.
OPAM-package your code and support the OCaml Platform!
Keep those contributions and this feedback flowing!
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 20 / 20

Contenu connexe

Tendances

First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class PatternsJohn De Goes
 
Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and HaskellHermann Hueck
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
3 kotlin vs. java- what kotlin has that java does not
3  kotlin vs. java- what kotlin has that java does not3  kotlin vs. java- what kotlin has that java does not
3 kotlin vs. java- what kotlin has that java does notSergey Bandysik
 
The Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect SystemThe Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect SystemJohn De Goes
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data scienceJohn Cant
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With ScalaKnoldus Inc.
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshuSidd Singh
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheoryKnoldus Inc.
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMSfawzmasood
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScripttmont
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with ScalaDenis
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 
2 kotlin vs. java: what java has that kotlin does not
2  kotlin vs. java: what java has that kotlin does not2  kotlin vs. java: what java has that kotlin does not
2 kotlin vs. java: what java has that kotlin does notSergey Bandysik
 
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...John De Goes
 

Tendances (20)

First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
 
Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and Haskell
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
3 kotlin vs. java- what kotlin has that java does not
3  kotlin vs. java- what kotlin has that java does not3  kotlin vs. java- what kotlin has that java does not
3 kotlin vs. java- what kotlin has that java does not
 
The Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect SystemThe Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect System
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data science
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With Scala
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
Scala Paradigms
Scala ParadigmsScala Paradigms
Scala Paradigms
 
Why Haskell
Why HaskellWhy Haskell
Why Haskell
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
2 kotlin vs. java: what java has that kotlin does not
2  kotlin vs. java: what java has that kotlin does not2  kotlin vs. java: what java has that kotlin does not
2 kotlin vs. java: what java has that kotlin does not
 
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
 
Comparing JVM languages
Comparing JVM languagesComparing JVM languages
Comparing JVM languages
 

Similaire à O caml2014 leroy-slides

The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of ScalaMartin Odersky
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - J...
Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - J...Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - J...
Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - J...Anne Nicolas
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudyYusuke Ando
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploitshughpearse
 
Numerical Simulation of Nonlinear Mechanical Problems using Metafor
Numerical Simulation of Nonlinear Mechanical Problems using MetaforNumerical Simulation of Nonlinear Mechanical Problems using Metafor
Numerical Simulation of Nonlinear Mechanical Problems using MetaforRomain Boman
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyTypesafe
 
Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance Coder Tech
 
Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014Renzo Borgatti
 
Rust and Eclipse
Rust and EclipseRust and Eclipse
Rust and EclipseMax Bureck
 
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...DrupalMumbai
 
Safe navigation in OCL
Safe navigation in OCLSafe navigation in OCL
Safe navigation in OCLEdward Willink
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshopjulien pauli
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 

Similaire à O caml2014 leroy-slides (20)

The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of Scala
 
OCL 2.5 plans
OCL 2.5 plansOCL 2.5 plans
OCL 2.5 plans
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - J...
Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - J...Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - J...
Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - J...
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
 
cp05.pptx
cp05.pptxcp05.pptx
cp05.pptx
 
C++ development within OOo
C++ development within OOoC++ development within OOo
C++ development within OOo
 
Numerical Simulation of Nonlinear Mechanical Problems using Metafor
Numerical Simulation of Nonlinear Mechanical Problems using MetaforNumerical Simulation of Nonlinear Mechanical Problems using Metafor
Numerical Simulation of Nonlinear Mechanical Problems using Metafor
 
Aligning OCL and UML
Aligning OCL and UMLAligning OCL and UML
Aligning OCL and UML
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance
 
Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014
 
C language
C languageC language
C language
 
Rust and Eclipse
Rust and EclipseRust and Eclipse
Rust and Eclipse
 
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
 
Safe navigation in OCL
Safe navigation in OCLSafe navigation in OCL
Safe navigation in OCL
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshop
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
64-bit Loki
64-bit Loki64-bit Loki
64-bit Loki
 

Dernier

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 

Dernier (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 

O caml2014 leroy-slides

  • 1. What’s new in OCaml 4.02 Xavier Leroy INRIA Paris-Rocquencourt OCaml Workshop, 2014-09-05 X. Leroy (INRIA) OCaml 4.02 OCaml 2014 1 / 20
  • 2. Recent releases Major release 4.01.0: (Sept. 2013) More lenient typing of ambiguous record labels and data constructors. Usability features: -short-path option to print inferred types more legibly. A lot of new warnings. Suggested corrections for misspelt identifiers. 135 bug fixes, 25 feature wishes. Major release 4.02.0: (Sept. 2014) A great many new features! 66 bug fixes, 18 feature wishes. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 2 / 20
  • 3. Unified matching on values and exceptions A classic programming problem: in let x = a in b, catch exceptions raised by a but not those raised by b. Wrong solution: put a try. . . with around let. let rec readfile ic accu = try let l = input_line ic in readfile ic (l :: accu) with End_of_file -> List.rev accu The try covers the recursive call to readfile and prevents it from being a tail call. Option-based encoding: correct but heavy. let rec readfile ic accu = match try Some(input_line ic) with End_of_file -> None with | Some l -> readfile ic (l :: accu) | None -> List.rev accu X. Leroy (INRIA) OCaml 4.02 OCaml 2014 3 / 20
  • 4. Unified matching on values and exceptions (Jeremy Yallop, Alain Frisch) In OCaml 4.02: the match a with construct is extended to analyse both the value of a and exceptions raised during a’s evaluation. let rec readfile ic accu = match input_line ic with | "" -> readfile ic accu | l -> readfile ic (l :: accu) | exception End_of_file -> List.rev accu Compilation preserves tail-call optimization for the recursive call. No allocation of intermediate Some results. The usual try. . . with construct is a special case: try ... with Not_found -> 0 ≡ match ... with x -> x | exception Not_found -> 0 X. Leroy (INRIA) OCaml 4.02 OCaml 2014 4 / 20
  • 5. Module aliases Common practice: bind an existing module to another name. module A = struct module M = AnotherModule ... end To have short qualified names M.x inside the body of A. To re-export a module or compilation unit as a submodule of another. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 5 / 20
  • 6. Module aliases module A = struct module M = AnotherModule ... end In classic OCaml, this binding is treated like any other definition module M = module-expr Typing: the equality A.M = AnotherModule is not recorded, can cause type errors with applicative functors. Compilation: accesses A.M.x sometimes go through more indirections than AnotherModule.x. Linking: a reference to A.M.x links in the whole of module A, not just AnotherModule. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 6 / 20
  • 7. Module aliases in OCaml 4.02 (Jacques Garrigue, Leo White) In 4.02, module M = AnotherModule is treated specially: During type-checking: the equality is recorded in the signature of the enclosing module A : sig module M = AnotherModule ... end During compilation: direct accesses to AnotherModule are generated. During linking: an access A.M.x no longer forces A to be linked in full, but only AnotherModule. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 7 / 20
  • 8. Application to libraries Goal: expose (to users) a library as a single unit L with submodules L.A, L.B, etc. Approach 1: single source Write and compile L as a single source file L.ml. Problem: does not scale. Approach 2: packing Put A, B in distinct source files A.ml, B.ml, separately compiled. Use ocamlopt -pack -o L.cmx to produce the single unit L. Problem: L is always linked in full. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 8 / 20
  • 9. Application to libraries New approach: use module aliases Put A, B in distinct source files L_A.ml, L_B.ml, separately compiled. (Note: the names L_A, L_B must be globally unique.) Write and compile a wrapper L.ml that re-exports them with short names: L.ml: module A = L_A module B = L_B Build and install an archive L.cmxa containing L_A, L_B, and L. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 9 / 20
  • 10. Mutability of strings For historical reasons, the string type of OCaml is mutable in place and has two broad uses: To represent text: let string_of_pair (x,y) = "(" ^ x ^ ", " ^ y ^")" As I/O buffers: let read_data ic n = let buf = String.create n in let len = Unix.read ic buf 0 n in String.sub buf 0 len OCaml programmers are very good at keeping the two uses distinct. But mistakes happen, and user code can be malicious. . . X. Leroy (INRIA) OCaml 4.02 OCaml 2014 10 / 20
  • 11. Pitfalls of mutable strings Mutating someone else’s string literals: (Lafosec study, ANSSI) # (Char.escaped ’t’).[1] <- ’n’;; - : unit = () # Char.escaped ’t’;; - : string = "n" # String.blit "true " 0 (string_of_bool false) 0 5;; - : unit = () # string_of_bool false;; - : string = "true " The disappearing key: let s = "foo" in Hashtbl.add tbl s 10; s.[1] <- ’x’; Hashtbl.find tbl "foo" X. Leroy (INRIA) OCaml 4.02 OCaml 2014 11 / 20
  • 12. Pitfalls of mutable strings LCF-style theorem proving: module ProofSystem : sig type thm val modusponens: thm -> thm -> thm val axiom_eqrefl: term -> thm val axiom_and: formula -> formula -> formula ... end By subverting the OCaml type system or using mutability of strings, it is possible to derive false results even in our LCF prover, but we restrict ourselves to ‘normal’ functional programming. J. Harrison, Handbook of Practical Logic and Automated Reasoning X. Leroy (INRIA) OCaml 4.02 OCaml 2014 12 / 20
  • 13. Towards immutable strings (Damien Doligez) In 4.02, two base types string (for text) and bytes (≈ byte arrays): By default, string and bytes are synonymous. They are incompatible if option -safe-string is given. In standard library String, functions that mutate strings are given types involving bytes and marked as deprecated: string.mli: val set : bytes -> int -> char -> unit [@@ocaml.deprecated] A new standard library module Bytes is provided with a full set of imperative functions operating over bytes, including conversion functions (with copy): bytes.mli: val set : bytes -> int -> char -> unit val of_string: string -> bytes val to_string: bytes -> string X. Leroy (INRIA) OCaml 4.02 OCaml 2014 13 / 20
  • 14. What changes? In default mode: All existing code compiles. Warnings when using String functions that mutate in place. In -safe-string mode: Values of type string are immutable. (Unless unsafe coercions are used.) I/O code and imperative constructions of strings need to be rewritten to use type bytes and library functions Bytes. A plea for developers of libraries: try to port your code to -safe-string mode and let us know how it worked. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 14 / 20
  • 15. Other novelties in OCaml 4.02 Language features: Explicitly generative functors. (Jacques Garrigue) A language of annotations over OCaml terms. Annotations are used by the compiler (e.g. to mark deprecated functions) and by preprocessors. (Alain Frisch) External preprocessors that rewrite the typed abstract syntax tree (-ppx option). (Alain Frisch) Open datatypes, extensible a posteriori with additional constructors. (Leo White) X. Leroy (INRIA) OCaml 4.02 OCaml 2014 15 / 20
  • 16. Other novelties in OCaml 4.02 Performance improvements: More aggressive constant propagation; dead code elimination; common subexpression elimination. (Xavier Leroy) More efficient pattern-matching over strings. (Benoˆıt Vaugon, Luc Maranget) More efficient and safer implementation of printf based on GADTs. (Benoˆıt Vaugon, Gabriel Scherer) More efficient representation of exceptions without arguments. (Alain Frisch) X. Leroy (INRIA) OCaml 4.02 OCaml 2014 16 / 20
  • 17. Other novelties in OCaml 4.02 Usability: New toplevel directives to query the environment, e.g. #show_type list or #show_module String. (Jacques Garrigue, Alain Frisch) New port: AArch64 (ARM in 64-bit mode). (Xavier Leroy, debugging by Richard Jones) Source reorganization: Camlp4 and Labltk were split off the core distribution and now live as independent projects — one opam install away. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 17 / 20
  • 18. This release brought to you by. . . Damien Doligez, release manager and general wizard. The core Caml development team: Jacques Garrigue, Alain Frisch, Fabrice Le Fessant, Xavier Leroy, Gabriel Scherer, Mark Shinwell, Leo White, Jeremy Yallop With much appreciated contributions from: Anil Madhavapeddy, Benoˆıt Vaugon, Daniel B¨unzli, David Allsopp, Hongbo Zhang, Jacques-Henri Jourdan, Jacques-Pascal Deplaix, John Whitington, Jonathan Protzenko, Jun Furuse, J´er´emie Dimino, Luc Maranget, Markus Mottl, Maxence Guesdon, Phil Denys, Pierre Chambart, Richard Jones, Romain Bardou, Stephen Dolan, St´ephane Glondu, Thomas Refis, Vladimir Brankov, ygrek. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 18 / 20
  • 19. What’s next? Bug-fix release 4.02.1. Language features: Various experiments in progress; nothing decided yet. Implementation: More optimizations, esp. improved inlining (Pierre Chambart). Ephemerons (Fran¸cois Bobot, Damien Doligez) GDB support (Mark Shinwell) Tweaks to support OPAM better. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 19 / 20
  • 20. In closing. . . Enjoy OCaml 4.02! Try to port your code to “safe string” mode: one day it might become the default. OPAM-package your code and support the OCaml Platform! Keep those contributions and this feedback flowing! X. Leroy (INRIA) OCaml 4.02 OCaml 2014 20 / 20