caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dario Teixeira <darioteixeira@yahoo.com>
To: OCaml mailing-list <caml-list@inria.fr>
Subject: [Caml-list] Locally abstract type with type parameters
Date: Wed, 20 Aug 2014 11:38:16 -0700	[thread overview]
Message-ID: <1408559896.43780.YahooMailNeo@web121705.mail.ne1.yahoo.com> (raw)

Hi,

Consider the signature LOGGER below, to be implemented by any module that
supposedly logs something wrapped under a custom monad:

  module type LOGGER =
  sig
      module Monad:
      sig
          type 'a t
          val return: 'a -> 'a t
          val bind: 'a t -> ('a -> 'b t) -> 'b t
      end

      val log: unit -> unit Monad.t
  end


We now define a functor that takes a LOGGER and defines a 'process' function
that operates under the monad.  But here's the twist: suppose that the function
that actually does the processing is defined elsewhere, in a module 'Foo'.
Moreover, instead of passing it the functions of the logger as independent
parameters, we deem it more convenient to pass the logger as a first-class
module:

  module Make (Logger: LOGGER) =
  struct
      let process x = Foo.actually_process (module Logger: LOGGER) x
  end


To avoid type-escaping-its-scope errors, we need to define a locally abstract
type in the implementation of 'actually_process'.  Something like this:

  let actually_process (type u) (module Logger: LOGGER with type 'a Monad.t = 'a u) x =
      let open Logger in
      let (>>=) t f = Monad.bind t f in
      Logger.log () >>= fun () ->
      Monad.return x


Which does not actually compile.  Is it at all possible to use a locally
abstract type when that type has type parameters?  And is there a solution
to this problem that does not require a) moving the implementation of
'actually_process' to the inside of a functor, or b) pass each function
of the first-class module as a separate parameter to 'actually_process'?

Thanks in advance for your time!
Best regards,
Dario Teixeira


             reply	other threads:[~2014-08-20 18:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-20 18:38 Dario Teixeira [this message]
2014-08-21  1:19 ` John F. Carr
2014-08-22  2:23   ` Benjamin Greenman
2014-08-24 16:39 ` Leo White
2014-08-26 14:33   ` Dario Teixeira

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=1408559896.43780.YahooMailNeo@web121705.mail.ne1.yahoo.com \
    --to=darioteixeira@yahoo.com \
    --cc=caml-list@inria.fr \
    /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).