Hi!

 

Your question inspired me to have a look at the modular implicits. I really like them. It seems that the argument of the implicit functor Show_logic also needs to be implicit, i.e., in curly braces. At least this worked for me.

 

Thomas

 

module type SHOW = sig

    type t

    val show : t -> string

end

 

let show {S : SHOW} x = S.show x;;

 

implicit module Show_int : (SHOW with type t = int) = struct

    type t = int

    let show = string_of_int

end

 

module type CORE = sig

  type 'a logic

 

  implicit module Show_logic {X: SHOW} : (SHOW with type t = X.t logic)

end

 

module Make(MK: CORE) = struct

  open MK

  (* open implicit MK (* doesn't help *) *)

 

  let foo (x: int logic) =

    let s = show x in (* Error: No instance found for implicit S. *)

    s

end

 

 

--- 

 

Dr. rer. nat. Thomas Martin Gawlitza, Diplom-Informatiker

Development Architect

Technology Office

office location: Potsdam (DE), POT04, A2.01, SAP Innovation Center, Konrad-Zuse-Ring 10, 14469 Potsdam

email: Thomas.Gawlitza@sap.com

phone: +49 331 9799 5408

mobile: +49 151 168 10 726

 

From: <caml-list-request@inria.fr> on behalf of Kakadu <kakadu.hafanana@gmail.com>
Reply-To: Kakadu <kakadu.hafanana@gmail.com>
Date: Wednesday 3 August 2016 at 01:17
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] Implicit question about searching for implicit module definition in the functor argument.

 

Hey, hackers.

 

I'm missing something obvious. Any fresh eyes around?

 

module type SHOW = sig

    type t

    val show : t -> string

end

 

let show {S : SHOW} x = S.show x;;

 

implicit module Show_int : (SHOW with type t = int) = struct

    type t = int

    let show = string_of_int

end

 

module type CORE = sig

  type 'a logic

 

  implicit module Show_logic(X: SHOW) : (SHOW with type t = X.t logic)

end

 

module Make(MK: CORE) = struct

  open MK

  open implicit MK (* doesn't help *)

 

  let foo (x: int logic) =

    let s = show x in (* Error: No instance found for implicit S. *)

    s

end

 

 

Kind regards,

Kakadu

 

--

Caml-list mailing list.  Subscription management and archives:

https://sympa.inria.fr/sympa/arc/caml-list

Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

Bug reports: http://caml.inria.fr/bin/caml-bugs