如何使OCaml编译器报告未使用的功能? [英] How to make OCaml compiler report unused functions?

查看:72
本文介绍了如何使OCaml编译器报告未使用的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何方法可以使OCaml编译器报告有关未使用的功能的警告?我用谷歌搜索,但是关于这个功能讨论的话题不多。

I wonder if is there any ways to make OCaml compiler report warnings about unused functions? I googled but there are not much topics discussed about this feature.

特别是,在下面的程序中,有两个函数 foo和 bar被声明,但在 _函数中未使用 bar 。因此,我认为OCaml编译器应将 bar报告为未使用的函数。

In particular, in the following program, there are two functions "foo" and "bar" which are declared but "bar" is not used in the "_" function. So I think that the OCaml compiler should report "bar" as an unused function.

let foo x y = x + y

let bar x y z = x + y + z         (* should be reported unused *)

let _ =
  let x = foo 1 2 in
  x


推荐答案

您需要定义(可能为空) .mli 接口文件,说明此模块导出的内容。否则,您只是在定义 bar 函数供其他模块使用。

You need to define a (possibly-empty) .mli interface file saying what this module exports. Otherwise, you're just defining a bar function for other modules to use.

(并确保您重新加上警告,当然)

(and make sure you're compiling with warnings on, of course)

这篇关于如何使OCaml编译器报告未使用的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆