首页 > 解决方案 > 令人困惑的 OCaml Base/Core 库弃用警告

问题描述

几个小时以来,我一直在尝试 Jane Street 的 Base / Core 库,但我对弃用警告感到非常困惑。

使用以下代码:

open Base
(* open Core *)
open Stdio

let _ = printf "%d" (4 mod 3)

我收到弃用警告:

Alert deprecated: Base.mod
[2016-09] this element comes from the stdlib distributed with OCaml.
Use (%), which has slightly different semantics, or Int.rem which is equivalent.

我知道我必须使用%or Int.rem,但是当我简单地使用时open Core,警告就会消失。该文档似乎没有对这些“弃用”进行太多说明。

此外,使用以下代码:

(* open Base *)
open Core
(* open Stdio *)

let _ = Out_channel.output_string stdout "Hello, OCaml"
let line = In_channel.input_line_exn stdin

我明白了

Alert deprecated: Core.stdin
[since 2016-04] Use [In_channel.stdin]

但令人惊讶的是,没有警报stdout

当我取消注释该(* open Stdio *)行时,我不再收到警告。我可以猜测 Stdio 模块可能会影响标准输入/标准输出,但我认为open Core这已经足够了,因为它取决于 Stdio 模块。

我用了

ocamlfind ocamlopt -o output.out -linkpkg -package base,stdio -thread output.ml

-package base,stdio,分别。

  1. 为什么我在使用 'mod' 时没有收到弃用警告open Core,如果它在我使用时警告我open Base

  2. 为什么我没有收到警报stdout

2-1。正常的open Stdio时候我也有必要open Core吗?

标签: ocamlocaml-core

解决方案


推荐阅读