Skip to content

Improve type error explanation for partially applied functor #12985

@art-w

Description

@art-w

I found the error message for partially applied functors to be confusing when the argument doesn't type check:

module type A = sig type a val missing : a end
module type B = sig type b end

module Make (A : A) (B : B) = struct end

module A_impl = struct type a = unit end

module Partial = Make (A_impl)
(*               ^^^^^^^^^^^^^
Error: The functor application is ill-typed.
       These arguments:
         A_impl
       do not match these parameters:
         functor (A : A) (B : B) -> ...
       1. An argument appears to be missing with module type A
       2. Modules do not match:
            A_impl : sig type a = unit end
          is not included in
            B
*)

It looks like some magic is happening to guess which functor parameter is missing, but when there are no good choices it introduces the missing arguments on the left rather than the right, leading to an unexpected error message (... assuming the partial application was otherwise correct)

module Partial = Make (<missing> : A) (A_impl : B)  (* current error *)

(* I expected the error to keep [A_impl] as the first parameter,
   optionally mentioning that the second argument [B] is missing *)
module Partial = Make (A_impl)
(*               ^^^^^^^^^^^^^
Error: The functor application is ill-typed.
       These arguments:
         A_impl
       do not match these parameters:
         functor (A : A) (B : B) -> ...
       1. Modules do not match:
            A_impl : sig type a = unit end
          is not included in
            A
          The value `missing' is required but not provided
       2. An argument appears to be missing with module type B
*)

(Obviously low priority considering the rarity of partially applied functors!)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions