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

Instance search is order-dependent #30

Open
yallop opened this issue Mar 17, 2015 · 0 comments
Open

Instance search is order-dependent #30

yallop opened this issue Mar 17, 2015 · 0 comments

Comments

@yallop
Copy link
Contributor

yallop commented Mar 17, 2015

Here's an example showing how varying the order of instance bindings affects whether the search succeeds:

m.ml:

module type T = sig type 'a t type s end

implicit module T_option = struct type 'a t = 'a option type s = int end
implicit module T_list = struct type 'a t = 'a list type s = int end
implicit module T_two = struct type 'a t = 'a * 'a type s = bool end

implicit functor F (L: T) (R: T) = struct
 type 'a t = 'a L.t R.t
 type s = R.s * L.s
end

let f (implicit N: T with type s = bool * int) (v: float N.t) : unit = ()

let x = f (Some 1.0, Some 2.0)

n.ml:

module type T = sig type 'a t type s end

implicit module T_list = struct type 'a t = 'a list type s = int end
implicit module T_option = struct type 'a t = 'a option type s = int end
implicit module T_two = struct type 'a t = 'a * 'a type s = bool end

implicit functor F (L: T) (R: T) = struct
 type 'a t = 'a L.t R.t
 type s = R.s * L.s
end

let f (implicit N: T with type s = bool * int) (v: float N.t) : unit = ()

let x = f (Some 1.0, Some 2.0)

Compiling:

$ ocamlc m.ml && echo ok
File "m.ml", line 14, characters 8-9:
Error: No instance found for implicit N.
$ ocamlc n.ml && echo ok
ok
$ 
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