What is the meaning of Warning 40: this record … contains fields that are not visible in the current scope

回眸只為那壹抹淺笑 提交于 2019-12-03 23:56:05

The type of the record is known in this case because you provided annotations. If you removed the annotations, the type would become unknown and the meaning of the code might change.

The philosophy of OCaml is that adding and removing type annotations should not affect the meaning of a program, so a warning is produced.

You can avoid this warning by bringing the relevant field into scope. Doing this for a field that is defined within a module A entails either opening A to bring its contents into scope, or qualifying the name of field with the module. For example:

module A = struct ... end

let test r = r.A.field

let test2 r = let open A in r.field

open A 

let test3 r = r.field
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!