realworldocaml/book

Code example fails on Mac due to Core.Sys deprecation in favor of Sys_unix

OliverBalfour opened this issue · 1 comments

I was reading the Lists and Patterns chapter and tried the recursive directory listing example halfway down. However, opening utop and trying to invoke Core.Sys.is_file_exn came up with a deprecation warning:

utop # Core.Sys.is_file_exn;;
Line 1, characters 0-20:
Alert deprecated: Core.Sys.is_file_exn
[since 2021-04] Use [Sys_unix]
Line 1, characters 0-20:
Alert deprecated: Core.Sys.is_file_exn
[since 2021-04] Use [Sys_unix]
- : [ `Use_Sys_unix ] = `Use_Sys_unix

utop # Core.Sys.is_file_exn "file";;
Error: This expression has type [ `Use_Sys_unix ]
       This is not a function; it cannot be applied.

I fixed this by using

open Base;;
#require "core_unix.sys_unix";;
module Sys = Sys_unix;;
Sys.is_file_exn "file";;

Environment:

  • Apple Silicon Mac (2021 MBP)
  • Affected OCaml 4.13.1 and 4.14.0, both installed with opam per your install instructions

I can confirm this is happening in Core.Command as well. Copying the md5 example and attempting to build results in the following.

% dune build File "bin/main.ml", line 25, characters 9-20: 25 | let () = Command.run ~version:"1.0" ~build_info:"RWO" command ^^^^^^^^^^^ Error (alert deprecated): Core.Command.run [since 2021-03] Use [Command_unix] File "bin/main.ml", line 25, characters 9-20: 25 | let () = Command.run ~version:"1.0" ~build_info:"RWO" command ^^^^^^^^^^^ Error: This expression has type [Use_Command_unix ]
This is not a function; it cannot be applied.
'