[cwn] Attn: Development Editor, Latest OCaml Weekly News

Alan Schmitt alan.schmitt at polytechnique.org
Mon Sep 16 23:42:33 PDT 2019


Hello

Here is the latest OCaml Weekly News, for the week of September 10 
to
17, 2019.

Table of Contents
─────────────────

OCaml 4.09.0+beta2
chartjs: OCaml bindings for Chart.js charting library
How does one print any type?
Interesting OCaml Articles
Dune 2.0.0 coming soon!
Old CWN


OCaml 4.09.0+beta2
══════════════════

  Archive:
  <https://sympa.inria.fr/sympa/arc/caml-list/2019-09/msg00010.html>


Florian Angeletti announced
───────────────────────────

  The release of OCaml 4.09.0 is approaching. We have created a 
  second
  beta version to help you adapt your softwares to the new 
  features
  ahead of the release.

  This new beta integrates in particular the fixes from 4.08.1 
  that were
  not yet part of the first beta due to the overlap between the 
  release
  of 4.08.1 and the first beta.

  If you tried to test the first beta, and were stopped by the 
  lack of
  working dune and ocamlfind, those issues has been fixed.

  The source code is available at these addresses:

  • <https://github.com/ocaml/ocaml/archive/4.09.0+beta2.tar.gz>
  • 
  <https://caml.inria.fr/pub/distrib/ocaml-4.09/ocaml-4.09.0+beta2.tar.gz>

  The compiler can also be installed as an OPAM switch with one of 
  the
  following commands.

  ┌────
  │ opam switch create ocaml-variants.4.09.0+beta2 
  --repositories=default,beta=git+https://github.com/ocaml/ocaml-beta-repository.git
  └────

  or

  ┌────
  │ opam switch create ocaml-variants.4.09.0+beta2+<VARIANT> 
  --repositories=default,beta=git+https://github.com/ocaml/ocaml-beta-repository.git
  └────

  where you replace <VARIANT> with one of these:
  • afl
  • default-unsafe-string
  • flambda
  • fp
  • fp+flambda

  We want to know about all bugs. Please report them here:
  <https://github.com/ocaml/ocaml/issues>

  Happy hacking

  — Florian "octachron" Angeletti, for the OCaml team


OCaml 4.09.0
╌╌╌╌╌╌╌╌╌╌╌╌

  (Changes that can break existing programs are marked with a "*")


◊ Code generation and optimizations:

  • #2278: Remove native code generation support for 32-bit Intel 
  macOS,
    iOS and other Darwin targets.  (Mark Shinwell, review by 
    Nicolas
    Ojeda Bar and Xavier Leroy)

  • #8507: Shorten symbol names of anonymous functions in Flambda 
  mode
    (the directory portions are now hidden) (Mark Shinwell, review 
    by
    Nicolás Ojeda Bär)

  • #7931, #1904: Add FreeBSD/aarch64 support (Greg V, review by
    Sébastien Hinderer, Stephen Dolan, Damien Doligez and Xavier 
    Leroy)

  • #8547: Optimize matches that are an affine function of the 
  input.
    (Stefan Muenzel, review by Alain Frisch, Gabriel Scherer)

  • #8681, #8699, #8712: Fix code generation with nested let rec 
  of
    functions.  (Stephen Dolan, Leo White, Gabriel Scherer and 
    Pierre
    Chambart, review by Gabriel Scherer, reports by Alexey 
    Solovyev and
    Jonathan French)


◊ Compiler user-interface and warnings:

  • * #2276: Remove support for compiler plugins and hooks (also 
  adds
    [Dynlink.unsafe_get_global_value]) (Mark Shinwell, Xavier 
    Clerc,
    review by Nicolás Ojeda Bär, Florian Angeletti, David Allsopp 
    and
    Xavier Leroy)

  • #2301: Hint on type error on int literal (Jules Aguillon, 
  review by
    Nicolás Ojeda Bär , Florian Angeletti, Gabriel Scherer and 
    Armaël
    Guéneau)

  • #2309: New options -with-runtime and -without-runtime in
    ocamlopt/ocamlc that control the inclusion of the runtime 
    system in
    the generated program.  (Lucas Pluvinage, review by Daniel 
    Bünzli,
    Damien Doligez, David Allsopp and Florian Angeletti)

  • #2314: Remove support for gprof profiling.  (Mark Shinwell, 
  review
    by Xavier Clerc and Stephen Dolan)

  • #3819, #8546 more explanations and tests for illegal 
  permutation
    (Florian Angeletti, review by Gabriel Scherer)

  • #8537: fix the -runtime-variant option for bytecode (Damien 
  Doligez,
    review by David Allsopp)

  • #8541: Correctly print multi-lines locations (Louis Roché, 
  review by
    Gabriel Scherer)

  • #8579: Better error message for private constructors of an
    extensible variant type (Guillaume Bury, review by many fine 
    eyes)


◊ Compiler distribution build system:

  • #2267: merge generation of header programs, also fixing 
  parallel
    build on Cygwin.  (David Allsopp, review by Sébastien 
    Hinderer)

  • #8514: Use boot/ocamlc.opt for building, if available. 
  (Stephen
    Dolan, review by Gabriel Scherer)


◊ Internal/compiler-libs changes:

  • #1579: Add a separate types for clambda primitives (Pierre 
  Chambart,
    review by Vincent Laviron and Mark Shinwell)

  • #1965: remove loop constructors in Cmm and Mach (Vincent 
  Laviron)

  • #1973: fix compilation of catches with multiple handlers 
  (Vincent
    Laviron)

  • #2190: fix pretty printing (using Pprintast) of "lazy …" 
  patterns
    and "fun (type t) -> …" expressions.  (Nicolás Ojeda Bär, 
    review by
    Gabriel Scherer)

  • #2228, #8545: refactoring the handling of .cmi files by moving 
  the
    logic from Env to a new module Persistent_env (Gabriel 
    Scherer,
    review by Jérémie Dimino and Thomas Refis)

  • #2229: Env: remove prefix_idents cache (Thomas Refis, review 
  by
    Frédéric Bour and Gabriel Scherer)

  • #2237, #8582: Reorder linearisation of Trywith to avoid a call
    instruction (Vincent Laviron and Greta Yorsh, additional 
    review by
    Mark Shinwell; fix in #8582 by Mark Shinwell, Xavier Leroy and 
    Anil
    Madhavapeddy)

  • #2265: Add bytecomp/opcodes.mli (Mark Shinwell, review by 
  Nicolas
    Ojeda Bar)

  • #2268: Improve packing mechanism used for building 
  compilerlibs
    modules into the Dynlink libraries (Mark Shinwell, Stephen 
    Dolan,
    review by David Allsopp)

  • #2277: Use newtype names as type variable names (Matthew Ryan)

  • #2280: Don't make more Clambda constants after starting Cmmgen 
  (Mark
    Shinwell, review by Vincent Laviron)

  • #2281: Move some middle-end files around (Mark Shinwell)

  • #2283: Add [is_prefix] and 
  [find_and_chop_longest_common_prefix] to
    [Misc.Stdlib.List] (Mark Shinwell, review by Alain Frisch and
    Stephen Dolan)

  • #2284: Add various utility functions to [Misc] and remove 
  functions
    from [Misc.Stdlib.Option] that are now in [Stdlib.Option] 
    (Mark
    Shinwell, review by Thomas Refis)

  • #2286: Functorise [Consistbl] (Mark Shinwell, review by 
  Gabriel
    Radanne)

  • #2291: Add [Compute_ranges] pass (Mark Shinwell, review by 
  Vincent
    Laviron)

  • #2292: Add [Proc.frame_required] and [Proc.prologue_required]. 
  Move
    tail recursion label creation to [Linearize]. Correctly 
    position
    [Lprologue] relative to [Iname_for_debugger] operations. 
    (Mark
    Shinwell, review by Vincent Laviron)

  • #2308: More debugging information on [Cmm] terms (Mark 
  Shinwell,
    review by Stephen Dolan)

  • #7878, #8542: Replaced TypedtreeIter with tast_iterator (Isaac
    "Izzy" Avram, review by Gabriel Scherer and Nicolás Ojeda Bär)

  • #8598: Replace "not is_nonexpansive" by "maybe_expansive". 
  (Thomas
    Refis, review by David Allsopp, Florian Angeletti, Gabriel 
    Radanne,
    Gabriel Scherer and Xavier Leroy)


◊ Runtime system:

  • #1725, #2279: Deprecate Obj.set_tag and Obj.truncate (Stephen 
  Dolan,
    review by Gabriel Scherer, Damien Doligez and Xavier Leroy)

  • #2075, #7729: rename _T macro used to support Unicode in the
    (Windows) runtime in order to avoid compiler warning (Nicolás 
    Ojeda
    Bär, review by Gabriel Scherer and David Allsopp)

  • * #2240: Constify "identifier" in struct custom_operations 
  (Cedric
    Cellier, review by Xavier Leroy)

  • #2250: Remove extra integer sign-extension in compare 
  functions
    (Stefan Muenzel, review by Xavier Leroy)

  • * #2293: Constify "caml_named_value" (Stephen Dolan, review by
    Xavier Leroy)

  • #8607: Remove obsolete macros for pre-2002 MSVC support 
  (Stephen
    Dolan, review by Nicolás Ojeda Bär and David Allsopp)

  • #8656: Fix a bug in [caml_modify_generational_global_root]
    (Jacques-Henri Jourdan, review by Gabriel Scherer)

  • #8787, #8788: avoid integer overflow in 
  caml_output_value_to_bytes
    (Jeremy Yallop, report by Marcello Seri)


◊ Standard library:

  • #2262: take precision (.<n>) and flags ('+' and ' ') into 
  account in
    printf %F (Pierre Roux, review by Gabriel Scherer)

  • #6148, #8596: optimize some buffer operations (Damien Doligez,
    reports by John Whitington and Alain Frisch, review by Jeremy 
    Yallop
    and Gabriel Scherer)


◊ Other libraries:

  • #2112: Fix Thread.yield unfairness with busy threads yielding 
  to
    each other.  (Andrew Hunter, review by Jacques-Henri Jourdan, 
    Spiros
    Eliopoulos, Stephen Weeks, & Mark Shinwell)

  • #7903, #2306: Make Thread.delay interruptible by signals again
    (Xavier Leroy, review by Jacques-Henri Jourdan and Edwin 
    Török)

  • #2248: Unix alloc_sockaddr: Fix read of uninitialized memory 
  for an
    unbound Unix socket. Add support for receiving abstract 
    (Linux)
    socket paths.  (Tim Cuthbertson, review by Sébastien Hinderer 
    and
    Jérémie Dimino)

  • #2289: Delete the vmthreads library. This library was 
  deprecated in
    4.08.0.  (Jérémie Dimino)

  • #2318: Delete the graphics library. This library is now 
  available as
    a separate "graphics" package in opam. Its new home is:
    <https://github.com/ocaml/graphics> (Jérémie Dimino, review by
    Nicolas Ojeda Bar, Xavier Leroy and Sébastien Hinderer)


◊ Tools:

  • #2221: ocamldep will now correctly allow a .ml file in an 
  include
    directory that appears first in the search order to shadow a 
    .mli
    appearing in a later include directory.  (Nicolás Ojeda Bär, 
    review
    by Florian Angeletti)


◊ Manual and documentation:

  • #8757: Rename Pervasives to Stdlib in core library 
  documentation.
    (Ian Zimmerman, review by David Allsopp)

  • #7584, #8538: Document .cmt* files in the "overview" of 
  ocaml{c,opt}
    (Oxana Kostikova, rewiew by Florian Angeletti)

  • #8515: manual, precise constraints on reexported types 
  (Florian
    Angeletti, review by Gabriel Scherer)


◊ Bug fixes:

  • #7156, #8594: make top level use custom printers if they are
    available (Andrew Litteken, report by Martin Jambon, review by
    Nicolás Ojeda Bär, Thomas Refis, Armaël Guéneau, Gabriel 
    Scherer,
    David Allsopp)
  • #3249: ocamlmklib should reject .cmxa files (Xavier Leroy)
  • #7937, #2287: fix uncaught Unify exception when looking for 
  type
    declaration (Florian Angeletti, review by Jacques Garrigue)

  • #2296: Fix parsing of hexadecimal floats with underscores in 
  the
    exponent.  (Hugo Heuzard and Xavier Leroy, review by Gabriel
    Scherer)

  • #8610, #8613: toplevel printing, consistent deduplicated name 
  for
    types (Florian Angeletti, review by Thomas Refis and Gabriel
    Scherer, reported by Xavier Clerc)

  • #8635, #8636: Fix a bad side-effect of the -allow-approx 
  option of
    ocamldep. It used to turn some errors into successes (Jérémie
    Dimino)

  • #8701, #8725: Variance of constrained parameters causes 
  principality
    issues (Jacques Garrigue, report by Leo White, review by 
    Gabriel
    Scherer)

  • #8777(partial): fix position information in some polymorphic 
  variant
    error messages about missing tags (Florian Angeletti, review 
    by
    Thomas Refis)

  • #8779, more cautious variance computation to avoid missing 
  cmis
    (Florian Angeletti, report by Antonio Nuno Monteiro, review by 
    Leo
    White)

  • #8800: Fix soundness bug in extension constructor inclusion 
  (Leo
    White, review by Jacques Garrigue)

  • #8810: Env.lookup_module: don't allow creating loops (Thomas 
  Refis,
    report by Leo White, review by Jacques Garrigue)

  • #8848: Fix x86 stack probe CFI information in caml_c_call and
    caml_call_gc (Tom Kelly, review by Xavier Leroy)

  • #8864, #8865: Fix native compilation of left shift by 
  (word_size -
    1) (Vincent Laviron, report by Murilo Giacometti Rocha, review 
    by
    Xavier Leroy)

  • #8862, #8871: subst: preserve scopes (Thomas Refis, report by 
  Leo
    White, review by Jacques Garrigue)

  • #8921, #8924: Fix stack overflow with Flambda (Vincent 
  Laviron,
    review by Pierre Chambart and Leo White, report by Aleksandr
    Kuzmenko)


chartjs: OCaml bindings for Chart.js charting library
═════════════════════════════════════════════════════

  Archive:
  <https://discuss.ocaml.org/t/ann-chartjs-ocaml-bindings-for-chart-js-charting-library/4363/1>


Alex announced
──────────────

  I'm pleased to announce `chartjs', OCaml bindings for [Chart.js]
  charting library and its popular extensions. The library relies 
  on
  `js_of_ocaml' bindings for browser API and follows `js_of_ocaml'
  [guides] for binding a JavaScript library.

  Line, bar, horizontal bar, pie and doughnut charts are currently
  supported.  The bindings are not full yet, some chart types and
  plugins are to be added later.

  • Installation: `opam install chartjs'.
  • Repository: <https://github.com/monstasat/chartjs-ocaml>
  • Library sage examples:
    <https://github.com/monstasat/chartjs-ocaml/tree/master/examples>
  • Online documentation and examples:
    <https://monstasat.github.io/chartjs-ocaml>

  Some auxiliary libraries are available providing bindings for 
  popular
  Chart.js plugins:
  • `chartjs-annotation'
  • `chartjs-streaming'
  • `chartjs-datalabels'
  • `chartjs-colorschemes'

  These libraries are also available via opam.

  Any feedback is highly appreciated.


[Chart.js] <http://chartjs.org>

[guides] <https://ocsigen.org/js_of_ocaml/dev/manual/bindings>


How does one print any type?
════════════════════════════

  Archive:
  <https://discuss.ocaml.org/t/how-does-one-print-any-type/4362/1>


Pinocchio asked
───────────────

  I just want to print any type (like a print statement in 
  python). I am
  just learning ocaml using the ocaml command interactively with 
  my
  script basically. How do I do this?


Alex replied
────────────

  You may also use the [ppx_deriving.show] plugin from the
  [ppx_deriving] library. This plugin is able to generate `'a -> 
  string'
  and `Format.formatter -> 'a -> unit' (where `'a' is the type you 
  want
  to print) functions which can then be used for value printing.

  ┌────
  │ type t =
  │ {  number : int
  │ ;  text : string
  │ }[@@deriving show]
  └────
  This will produce a `show' and `pp' functions of type `t -> 
  string'
  and `Format.formatter -> t -> unit', which can then be used as

  ┌────
  │ let v = { number = 2; text = "Hello world"} in
  │ print_endline (show v)
  └────

  or

  ┌────
  │ let v = { number = 2; text = "Hello world"} in
  │ let s = Format.asprintf "%a" pp v in
  │ print_endline s
  └────
  Of course, you can always define such functions for the needed 
  types
  by yourself.

  As I can see, almost every library introducing a new type also
  provides pretty-printing (kinda `pp' in this example) functions 
  out of
  the box.


[ppx_deriving.show]
<https://github.com/ocaml-ppx/ppx_deriving#plugin-show>

[ppx_deriving] <https://github.com/ocaml-ppx/ppx_deriving>


progman also replied
────────────────────

  The same basic printing as the toplevel can be had with:

  [http://github.com/progman1/genprintlib ] (general value 
  printing in
  compiled code)

  Available through the official opam repository: opam install 
  genprint


[http://github.com/progman1/genprintlib ]
<http://github.com/progman1/genprintlib>


Ivan Gotovchits also replied
────────────────────────────

  There is no such facility in OCaml. OCaml is not an interpreted
  language with a dynamic type system. When a program is compiled 
  all
  types are erased, so it is impossible in runtime to reflect a 
  value to
  its type. And yes, as you've already pointed out, when you 
  interact
  with OCaml using interactive toplevel there is some generic 
  printing
  facility, but this is a very special case because you're not 
  really
  running a program, but interactively compile it.

  So, you have to accept this fact and learn how to program in 
  OCaml
  using OCaml ways of doing things. First of all, learn how to use 
  the
  `Format.printf' function. This is a generic function that takes 
  the
  `format' specification and arguments and prints them, e.g.,

  ┌────
  │ open Format
  │
  │ let () =
  │   printf "Hello, %s world\n%!" "cruel";
  │   printf "Hello, %d times!\n%!" 42
  └────

  As you can see, the special format specifiers, like `%s' or `%d'
  specify the type of an argument. So `%d' expects one argument of 
  type
  `int', and `%s' expects one of `string', there is also `%c' for 
  `char'
  , `%b' for `bool' and so on.

  There is also a generic `%a' specifier, which expects not one
  argument, but two – a function, that will tell how to print the
  argument, and the argument itself. It is used to print values of
  abstract types, hence the name `%a'. There is a convention, that
  modules that define abstract types also provide a function 
  called `pp'
  which specifies how this value should be printed, e.g.,

  ┌────
  │ let () = printf "Hello, abstract student %a\n%!" Student.pp s
  └────

  Where the `Student' module might be defined as

  ┌────
  │ struct Student : sig
  │    type t
  │    val create : string -> int -> t
  │    val pp : Format.formatter -> t -> unit
  │ end = struct
  │    type t = {name : string; cls : int}
  │    let create name cls  = {name; cls}
  │    let pp ppf {name; cls} =
  │       Format.fprintf ppf "%s of %d" name cls
  │ end
  └────

  That is roughly how we print everything in OCaml :)


Interesting OCaml Articles
══════════════════════════

  Archive:
  <https://discuss.ocaml.org/t/interesting-ocaml-articles/1867/50>


Yotam Barnoy said
─────────────────

  <https://tarides.com/blog/2019-09-13-decompress-experiences-with-ocaml-optimization.html>


Ryan Slade also said
────────────────────

  Interesting performance comparison with quite a few languages 
  when
  writing a user space network driver:

  <https://github.com/ixy-languages/ixy-languages>


Dune 2.0.0 coming soon!
═══════════════════════

  Archive: 
  <https://discuss.ocaml.org/t/dune-2-0-0-coming-soon/4102/2>


Jérémie Dimino announced
────────────────────────

  Update: after thinking about this more and working more towards
  preparing Dune 2.0.0, we made the following changes compared to 
  this
  post:

  • The source code of Dune itself will remain compatible with the 
  last
    3 released versions of OCaml rather than just the last one. 
    i.e. if
    4.08 is the last released version of OCaml when Dune 2.0.0 is
    released then Dune 2.0.0 will be guaranteed to build with 
    OCaml
    4.06, 4.07 and 4.08. We still plan to provide an easy way to 
    install
    Dune 2.0.0 in older opam switches
  • Dune 2.0.0 will not be able to read jbuild files at all. Only 
  `dune
    upgrade' will still be able to read them in order to upgrade 
    them


Old CWN
═══════

  If you happen to miss a CWN, you can [send me a message] and 
  I'll mail
  it to you, or go take a look at [the archive] or the [RSS feed 
  of the
  archives].

  If you also wish to receive it every week by mail, you may 
  subscribe
  [online].

  [Alan Schmitt]


[send me a message] <mailto:alan.schmitt at polytechnique.org>

[the archive] <http://alan.petitepomme.net/cwn/>

[RSS feed of the archives] 
<http://alan.petitepomme.net/cwn/cwn.rss>

[online] <http://lists.idyll.org/listinfo/caml-news-weekly/>

[Alan Schmitt] <http://alan.petitepomme.net/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20190917/505a5c85/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20190917/505a5c85/attachment-0001.pgp>


More information about the caml-news-weekly mailing list