Search code examples
ocamlfunctor

OCaml functor Set.Make/Map.Make weird annotation in VSCode


enter image description here

Why in the world is there a /1. between Ord: Set and OrderedType -> ?

This shows up for Set.Make and for Map.Make in VSCode environment, and possibly for other built-in Make functors as well.

See code below for an example, if you hover over the Set.Make function in VSCode, it will say as the first line "functor (Ord : Set/1.OrderedType)".

type t = { street : string; city : string }

module Address = struct
  type t = { street : string; city : string }

  let compare a1 a2 =
    match compare a1.city a2.city with
    | 0 -> compare a1.street a2.street
    | x -> x
end

module AddressSet = Set.Make (Address)

Solution

  • Pending information from Yanny, this looks like you've either redefined the module or VSCode is being proactive. Consider the following simple example:

    % rlwrap ocaml
    OCaml version 5.0.0~rc1
    Enter #help;; for help.
    
    # module type S = sig
        type t
      end
      
      module A (T : S) = struct
        type t = T.t
      end;;
    module type S = sig type t end
    module A : functor (T : S) -> sig type t = T.t end
    # module B = A (Int)
      
      let foo (x: B.t) = x + 1;;
    module B : sig type t = Int.t end
    val foo : B.t -> int = <fun>
    # module B = A (Float)
      
      let bar (x : B.t) = x +. 1.;;
    module B : sig type t = Float.t end
    val bar : B.t -> float = <fun>
    # foo;;
    - : B/2.t -> int = <fun>
    

    Note the B/2 designation for the type in the signature for foo? This is because I've shadowed the name B for the earlier module, but foo still has access to it.