ocaml-modular-implicits icon indicating copy to clipboard operation
ocaml-modular-implicits copied to clipboard

Module name leak in nested types

Open mrmr1993 opened this issue 4 years ago • 2 comments

When a function accepts multiple implicit arguments and their types nest as type parameters, the later implicit argument is not resolved. This appears to be an actual failure rather than a printing error: see the last evaluation.

$ rlwrap boot/ocamlrun ./ocaml -nostdlib -I stdlib -noinit
        OCaml version 4.02.1+dev0-2014-08-29

# module type TYPE1 = sig type _ t end;;
module type TYPE1 = sig type _ t end
# let f {M : TYPE1} {N : TYPE1} (x : int M.t N.t M.t) = x;;
val f : {M : TYPE1} -> {N : TYPE1} -> int M.t N.t M.t -> int M.t N.t M.t =
  <fun>
# implicit module Option_type = struct type 'a t = 'a option end;;
implicit module Option_type : sig type 'a t = 'a option end
# f {Option_type} {Option_type};;
- : int Option_type.t N.t Option_type.t ->
    int Option_type.t N.t Option_type.t
= <fun>
# let g x = f x;;
val g :
  int Option_type.t N.t Option_type.t -> int Option_type.t N.t Option_type.t =
  <fun>
# g (Some (Some (Some 15)));;
Error: This expression has type 'a option
       but an expression was expected of type int Option_type.t N.t

mrmr1993 avatar Dec 28 '20 06:12 mrmr1993

Interesting. @trefis since he's been working on a rebased version of the prototype recently and I'm not sure he is following this repo.

lpw25 avatar Dec 28 '20 09:12 lpw25

Possibly the same bug (discovered by @dvlasits and @pxeger):

module type Mk = sig type 'a t val mk : 'a -> 'a t end
module type T = sig type t end
module Lst = struct type 'a t = 'a list let mk x = [x] end

let test {M : Mk} {T : T} (f : T.t) : T.t M.t = M.mk f
let test2 = test {Lst} {Int64} 0L

This gives

val test : {M : Mk} -> {T : T} -> T.t -> T.t M.t = <fun>
val test2 : T.t Lst.t = [<abstr>]

i.e. the type T.t in the return type of test is not resolved to Int64 in the call from test2.

yallop avatar Sep 12 '23 10:09 yallop