Search code examples
ocamlocaml-core

How do I avoid shadowing an stdlib module in Ocaml?


I have a program that uses the Bytes module from the Ocaml standard library and also opens the Core_kernel.Std module at the top of the file

open Core_kernel.Std

...

   let let buf = Bytes.make bom_len '\x00' in

The problem I am having is that the latest version of Core_kernel introduced a new Bytes module that is shadowing the one from the standard library, which is resulting in a Unbound value Bytes.make compilation error.

Is there a way to solve this naming issue without getting rid of the open at the top of the file? If I did that it would require changing lots of things.


Solution

  • You could provide an alternative name for the Bytes module as such:

    module B = Bytes
    
    open Core_kernel.Std
    
    let buf = B.make 10 '\x00'
    

    and then do a search-replace in your code to change Bytes by B.

    Another solution would be to avoid using open, but this would require a lot of changes in your code, I guess.