The state of OCaml, 2012 Xavier Leroy INRIA Paris-Rocquencourt OCaml Users and Developers Workshop, 2012-09-14 X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 1 / 17
Outline OCaml development news 1 OCaml community news 2 X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 2 / 17
The new major release: OCaml 4.00 s d s l t e n s s fi a e e s l i l d s u e r u s a n r d s t d 2 v o r s n o o e a c e m e c m t l e c k m t i r s h a a s T d u e p t p c s v n r g i a D h , o i y a r s s l a p z A m c e r s r u a - s G d o t y t s c L s c l e m a o e r e l l R i P e y j C F b b l o O a OCaml 4 P l OCaml 3 OCaml2 OCaml1 CSL 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 3 / 17
What’s new Language features: Generalized Algebraic Data Types More lightweight support for modules packed as first-class values. Implementation features: Exposing rich typed ASTs and compiler internals (for IDEs and more) Lots of new warnings Revamped ARM code generator Improvements in marshaling and generic hashing. Development process: More external contributions 160 issues fixed, 50 feature wishes granted More rigorous (but slow) release process. X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 4 / 17
Zoom #1: Generalized Algebraic Data Types (GADTs) J. Garrigue, J. Le Normand (U. Nagoya) A (seemingly minor) extension to the declaration of variant data types that enables programmers to 1 express properties of data structures via type equalities; 2 have the type-checker enforce these properties. X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 5 / 17
Without GADTs: tagged interpreters type expr = | Lit of string | Pair of expr * expr | Fst of expr | Snd of expr and value = (* results of evaluation *) | VString of string (* ‘‘tagged’’ with their types *) | VPair of value * value let rec eval : expr -> value = function (* produces a tagged value *) | Lit s -> VString s | Pair(e1, e2) -> VPair(eval e1, eval e2) | Fst e1 -> (match eval e1 with VPair(v1, v2) -> v1 | _ -> raise Error) | Snd e1 -> (match eval e1 with VPair(v1, v2) -> v2 | _ -> raise Error) (* dynamic typing during evaluation *) X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 6 / 17
With GADTs: tagless interpreters Can define τ expr as the type of symbolic expressions that safely evaluate to a Caml value of type τ . type _ expr = | Lit: string -> string expr | Pair: ’a expr * ’b expr -> (’a * ’b) expr | Fst: (’a * ’b) expr -> ’a expr | Snd: (’a * ’b) expr -> ’b expr The evaluator, then, needs not tag result values, and cannot fail. let rec eval : type v. v expr -> v = function (* v = string here *) | Lit s -> s | Pair(e1, e2) -> (eval e1, eval e2) (* v = v1 * v2 here *) | Fst e -> fst (eval e) (* statically safe *) | Snd e -> snd (eval e) X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 7 / 17
Zoom #2: working with typed ASTs T. Turpin, F. Le Fessant, T. Gazagnaire (OCamlPro) A new compiler option, -bin-annot , causing the production of a .cmt file containing a rich Abstract Syntax Tree annotated with Source file locations Scoping and binding information for identifiers Types inferred by the typechecker. (Generalizes the -annot option, which generated only a subset of this information, in an Emacs-specific format.) X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 8 / 17
The OCaml compilation chain, before 4.00 Source Parsetree: (produced by the parser) Very close to source text Parsetree Annotated by source locations (file name, line #, column #) Typedtree No types, no scoping information Lambda Typedtree: (produced by the typechecker) Bytecode Annotated by (inferred) types ULambda Explicit scoping and binding of idents C -- Some source constructs eliminated ( open , include , type constraints) Mach No source locations Linear All source constructs represented Same location info as in Parsetree Assembly X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 9 / 17
The OCaml compilation chain, in 4.00 Source Parsetree: (produced by the parser) Very close to source text Parsetree Annotated by source locations (file name, line #, column #) Typedtree No types, no scoping information .cmt file Lambda Typedtree: (produced by the typechecker) Bytecode Annotated by (inferred) types ULambda Explicit scoping and binding of idents C -- Some source constructs eliminated ( open , include , type constraints) Mach No source locations Linear All source constructs represented Same location info as in Parsetree Assembly X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 9 / 17
Using typed ASTs Current use: for IDEs (e.g. TypeRex, OCamlSpotter) show inferred types; jump to definition; scoping-aware identifier renaming; type-aware completion; etc. Possible future use: for code generation Camlp4-style preprocessing that has access to type & scope info. Typedtree Parsetree Camlp* Caveat: currently, no stable API to work on typed ASTs; must use compiler internal modules. X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 10 / 17
Using typed ASTs Current use: for IDEs (e.g. TypeRex, OCamlSpotter) show inferred types; jump to definition; scoping-aware identifier renaming; type-aware completion; etc. Possible future use: for code generation Camlp4-style preprocessing that has access to type & scope info. Typedtree Parsetree Camlp* ??? Caveat: currently, no stable API to work on typed ASTs; must use compiler internal modules. X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 10 / 17
This release brought to you by . . . J´ er´ emie Dimino Xavier Thomas Clerc Gazagnaire Alain Jacques Frisch Garrigue Wojciech Jacques Meyer Le Normand Damien Doligez Fabrice Xavier Le Fessant Leroy Tiphaine Benedikt Turpin Meurer Gabriel Jonathan (More help is welcome.) Scherer Protzenko X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 11 / 17
Future directions A bug-fix release 4.00.1 this Fall. Work in progress on: Name space management Run-time representations of types. Performance improvements (native compiler, run-time system). Shedding more weight off the core system. (By splitting off some libraries and tools as independent projects.) X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 12 / 17
Outline OCaml development news 1 OCaml community news 2 X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 13 / 17
News from the community (not exhaustive) Some new or recently open-sourced projects: TypeRex (OCamlPro’s IDE) OPAM (OCamlPro’s package manager) Opa (MLstate’s Web programming framework) Mirage (OCaml as a Xen guest OS) JS-of-OCaml (OCaml running in any browser) Functory and Parmap (parallel computation) ZArith (arbitrary-precision integers) Async (Jane Street’s lightweight cooperative threads) X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 14 / 17
News from the community (not exhaustive) New releases of major libraries and frameworks, such as: Batteries and Core (comprehensive standard libraries) Frama-C (static analysis framework) Ocsigen (Web programming framework) OCaml “companion tools” ODT (Eclipse plug-in) OUnit (unit testing framework) Plasma (distributed file system and map-reduce) X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 15 / 17
News from the community (not exhaustive) Cool factor: OCaml iPhone/iPad apps (psellos.com, M. Hayden, J. Kimmit) TryOCaml (toplevel in browser) Textbooks: Real-World OCaml (J. Hickey, A. Madhavepeddy, Y. Minsky) (soon?) Think OCaml: How to Think Like a Computer Scientist (N. Monje and A .Downey) Programmation de droite ` a gauche (et vice-versa) (P. Manoury) X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 16 / 17
In closing. . . A lively language; a lively implementation; a very lively community. Some growing pains. Many individual contributions, deserve better integration & accessibility. High hopes in a future OCaml Platform. X. Leroy (INRIA) The state of OCaml, 2012 OUD 2012 17 / 17
Recommend
More recommend