SlideShare a Scribd company logo
1 of 20
Download to read offline
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 identi๏ฌers.
135 bug ๏ฌxes, 25 feature wishes.
Major release 4.02.0: (Sept. 2014)
A great many new features!
66 bug ๏ฌxes, 18 feature wishes.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 2 / 20
Uni๏ฌed 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
Uni๏ฌed 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 quali๏ฌed 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 de๏ฌnition
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 ๏ฌle L.ml.
Problem: does not scale.
Approach 2: packing
Put A, B in distinct source ๏ฌles 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 ๏ฌles 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 bu๏ฌ€ers:
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 e๏ฌƒcient pattern-matching over strings.
(Benoห†ฤฑt Vaugon, Luc Maranget)
More e๏ฌƒcient and safer implementation of printf based on GADTs.
(Benoห†ฤฑt Vaugon, Gabriel Scherer)
More e๏ฌƒcient 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 o๏ฌ€ 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 Re๏ฌs, Vladimir
Brankov, ygrek.
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 18 / 20
Whatโ€™s next?
Bug-๏ฌx 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 ๏ฌ‚owing!
X. Leroy (INRIA) OCaml 4.02 OCaml 2014 20 / 20

More Related Content

What's hot

friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
Sidd Singh
ย 

What's hot (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
ย 

Similar to O caml2014 leroy-slides

20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
Yusuke Ando
ย 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
hughpearse
ย 
Aligning OCL and UML
Aligning OCL and UMLAligning OCL and UML
Aligning OCL and UML
Edward Willink
ย 
Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014
Renzo Borgatti
ย 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshop
julien pauli
ย 

Similar to 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
ย 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
anilsa9823
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
ย 

Recently uploaded (20)

SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
ย 
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธcall girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
ย 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
ย 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
ย 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
ย 
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
ย 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
ย 
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS LiveVip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
ย 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
ย 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
ย 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
ย 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
ย 

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 identi๏ฌers. 135 bug ๏ฌxes, 25 feature wishes. Major release 4.02.0: (Sept. 2014) A great many new features! 66 bug ๏ฌxes, 18 feature wishes. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 2 / 20
  • 3. Uni๏ฌed 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. Uni๏ฌed 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 quali๏ฌed 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 de๏ฌnition 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 ๏ฌle L.ml. Problem: does not scale. Approach 2: packing Put A, B in distinct source ๏ฌles 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 ๏ฌles 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 bu๏ฌ€ers: 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 e๏ฌƒcient pattern-matching over strings. (Benoห†ฤฑt Vaugon, Luc Maranget) More e๏ฌƒcient and safer implementation of printf based on GADTs. (Benoห†ฤฑt Vaugon, Gabriel Scherer) More e๏ฌƒcient 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 o๏ฌ€ 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 Re๏ฌs, Vladimir Brankov, ygrek. X. Leroy (INRIA) OCaml 4.02 OCaml 2014 18 / 20
  • 19. Whatโ€™s next? Bug-๏ฌx 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 ๏ฌ‚owing! X. Leroy (INRIA) OCaml 4.02 OCaml 2014 20 / 20