caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Yotam Barnoy <yotambarnoy@gmail.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Expanding functors
Date: Thu, 27 Aug 2015 15:35:43 +0200	[thread overview]
Message-ID: <CAPFanBH6yFtqc_ikouKuQDrR8dvZF6S7bW==EsgNv6LbJx8ZsQ@mail.gmail.com> (raw)
In-Reply-To: <CAN6ygOkt00dsKkZPvKybbeHa-yw_s7tKC2LwHPGcRPDCUBz51Q@mail.gmail.com>

I don't follow. Doesn't

  module MakeBetter (K : sig include Map.OrderedType val show : t ->
string end) =
  struct
    include Map.Make(K)
    let show show_val m = List.show (Pair.show K.show show_val) (bindings m)
  end

suit your need?

The extensibility problem I see is that you cannot use the map's
internal representation because it is an abstract type -- which
prevents from efficiently implementing certain operations -- but this
is unrelated to being a functor.

On Thu, Aug 27, 2015 at 3:29 PM, Yotam Barnoy <yotambarnoy@gmail.com> wrote:
> One problem I've commonly encountered in OCaml is the inability to expand
> the interface of functors after they've been created (I'm not talking about
> post-application). For example, Map.Make in the stdlib takes an OrderedType
> module which contains only the compare function. What happens if I want to
> add something to this interface, such as a show function? I have to copy the
> whole implementation of Map.Make into my own file to modify it. Compare this
> to the ability to 'include' a regular module and just add the new
> functionality, and to take the type of a module and expand that type as
> needed. Functors are severely lacking in this regard.
>
> What do people think of this idea -- of allowing functors to be expanded?
> Ideally, expanding a functor would allow for both replacing its argument
> type (as in the example I gave) and for adding a second/third functor
> argument type (so Map.Make(OrderedType) would become
> Map.Make(OrderedType)(Show).
>
> -Yotam

  parent reply	other threads:[~2015-08-27 13:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-27 13:29 Yotam Barnoy
2015-08-27 13:33 ` Drup
2015-08-27 13:35 ` Gabriel Scherer [this message]
2015-08-27 14:17   ` Yotam Barnoy

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='CAPFanBH6yFtqc_ikouKuQDrR8dvZF6S7bW==EsgNv6LbJx8ZsQ@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=yotambarnoy@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).