Subject: [Caml-list] Filename.temp_dir_name

From: Sébastien Hinderer <[email-masked]>
Date: Thu, 23 Oct 2014 14:12:02 +0200

Dear all,

In Ocaml 4.02.0, filename.mli says that temp_dir_name is deprecated
since 3.09.1 and that get_temp_dir_name should be used instead, but this
function does not seem to be deined in e.g.the sources of
ocaml-3.10.0+beta.

Any hint?

Thanks,
Sébastien.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

---

From: David Allsopp <[email-masked]>
Date: Thu, 23 Oct 2014 12:50:20 +0000

Sébastien Hinderer wrote:
> Dear all,
> 
> In Ocaml 4.02.0, filename.mli says that temp_dir_name is deprecated since
> 3.09.1 and that get_temp_dir_name should be used instead, but this
> function does not seem to be deined in e.g.the sources of ocaml-
> 3.10.0+beta.

You've not quite read the sources correctly - the function temp_dir_name was *introduced* in 3.09.1 (that's the @since) and deprecated in 4.00.0 when get_temp_dir_name was introduced (deprecated functions became a bit more visible in 4.02 because of the new [@@deprecated] attribute - although warning 3 existed, I think that was only language features beforehand).

If you need to write code for 4.x which is also backwards compatible, you'll need to introduce a compatibility layer - ExtLib/Batteries contain examples of how to do this (especially the Unix modules in Batteries, which have to allow for different constructors in different version of OCaml sum types).

Essentially, you'll create something like CompatibilityLayer.ml which your build system will generate as:

module Filename = Filename

for OCaml >= 4.00.0, and:

module Filename = struct
  include Filename

  let get_temp_dir_name = (* ... code for get_temp_dir_name *)

  (* ... any other 4.00.0 functions back-ported *)
end

for OCaml < 4.00.0. Then in each of your actual source files you'll simply add

open CompatibilityLayer

at the top. See also the bytes package in findlib >= 1.5 (doing the same thing for the OCaml 4.02 Bytes module).

HTH,

David