caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Locally abstract type with type parameters
@ 2014-08-20 18:38 Dario Teixeira
  2014-08-21  1:19 ` John F. Carr
  2014-08-24 16:39 ` Leo White
  0 siblings, 2 replies; 5+ messages in thread
From: Dario Teixeira @ 2014-08-20 18:38 UTC (permalink / raw)
  To: OCaml mailing-list

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-08-26 14:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-20 18:38 [Caml-list] Locally abstract type with type parameters Dario Teixeira
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

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).