caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Gawlitza, Thomas" <thomas.gawlitza@sap.com>
To: Kakadu <kakadu.hafanana@gmail.com>, Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Implicit question about searching for implicit module definition in the functor argument.
Date: Wed, 3 Aug 2016 05:18:57 +0000	[thread overview]
Message-ID: <032632D8-A18E-4F9D-846B-F18860440120@sap.com> (raw)
In-Reply-To: <CAGmVoG04Zz3ne_HRREsXtmHvEm6Wz_sk7TdTg1++VituHw+-Zg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2293 bytes --]

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


[-- Attachment #2: Type: text/html, Size: 12094 bytes --]

  reply	other threads:[~2016-08-03  5:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-02 23:17 Kakadu
2016-08-03  5:18 ` Gawlitza, Thomas [this message]
2016-08-03 20:53   ` Kakadu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=032632D8-A18E-4F9D-846B-F18860440120@sap.com \
    --to=thomas.gawlitza@sap.com \
    --cc=caml-list@inria.fr \
    --cc=kakadu.hafanana@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).