Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No instance found with open implicit and type alias #57

Open
gadmm opened this issue May 12, 2019 · 0 comments
Open

No instance found with open implicit and type alias #57

gadmm opened this issue May 12, 2019 · 0 comments

Comments

@gadmm
Copy link

gadmm commented May 12, 2019

The behaviour of the following example is unexpected:

module type Print = sig
  type t
  val f : t -> unit
end

implicit module Int = struct
  type t = int

  let f _ = ()
end

module type Pair = sig
  type ('a,'b) t = 'a * 'b

  implicit module Make {A:Print} {B:Print} : Print with type t = (A.t, B.t) t
  (* (*works*) implicit module Make {A:Print} {B:Print} : Print with type t = A.t * B.t *)

  val create : 'a -> 'b -> ('a,'b) t
end

module Pair : Pair = struct
  type ('a,'b) t = 'a * 'b

  implicit module Make {A:Print} {B:Print} = struct
    type t = A.t * B.t

    let f _ = ()
  end

  let create x y = (x,y)
end

open implicit Pair
(* (*works*) open Pair *)

let print {A:Print} (x:A.t) = A.f x

let _ = print (Pair.create 3 3)

It fails to compile with Error: No instance found for implicit A.. What I would expect is that it correctly resolves the module Pair.Make {Int} {Int}.

My use-case of interest is when type ('a,'b) t is abstract, but this seems irrelevant for the problem.

It compiles as expected when you either replace the type by its definition in the declaration of Make (uncomment the first comment) or if you replace open implicit with a plain open (uncomment the second comment).

I looked at other bugs, but it did not seem to fit already-reported ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant