From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 799627F16E for ; Thu, 27 Aug 2015 16:18:02 +0200 (CEST) IronPort-PHdr: 9a23:r1oiCRIk7eO2u+HcS9mcpTZWNBhigK39O0sv0rFitYgUIvnxwZ3uMQTl6Ol3ixeRBMOAu6kC1bad7PiocFdDyKjCmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TWM5DIfUi/yKRBybrysXNWC1ILpi6vto9X6WEZhunmUWftKNhK4rAHc5IE9oLBJDeIP8CbPuWZCYO9MxGlldhq5lhf44dqsrtY4q3wD89pozcNLUL37cqIkVvQYSW1+ayFmrPHs4DbKRxGO639UaW4WnwBFGUCR4xjwRJb8tm3hvepwwiSAFcLzRLEwHz+l6vE4ZgXvjXI2MCIw9Sn9g9Z2i7MT9AOmuxV6yYfOZoaEHPV7d6LZO9gdQDwSDY5qSyVdD9bkPMM0BO0bMLMd9tGlqg== Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=yotambarnoy@gmail.com; spf=Pass smtp.mailfrom=yotambarnoy@gmail.com; spf=None smtp.helo=postmaster@mail-yk0-f171.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of yotambarnoy@gmail.com) identity=pra; client-ip=209.85.160.171; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="yotambarnoy@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of yotambarnoy@gmail.com designates 209.85.160.171 as permitted sender) identity=mailfrom; client-ip=209.85.160.171; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="yotambarnoy@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-yk0-f171.google.com) identity=helo; client-ip=209.85.160.171; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="postmaster@mail-yk0-f171.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BnAQBzG99VlKugVdFdhFgGgx3CUQKBKAc7EQEBAQEBAQEBEAEBAQEHCwsJHzCCHYIGAQEBAwESEQQZARsdAQMBCwYFBAcNKgICIQEBEQEFARwGExsHh3YBAwoIpVKBLz4xi0CBbIJ5iigKGScNVoRZAQEBAQEBBAEBAQEBARYBBQ6LU4JPgjwHgmmBQwWVPYsGgW2BSpFbg1CCHxIjgRcXhCoiM4JNAQEB X-IPAS-Result: A0BnAQBzG99VlKugVdFdhFgGgx3CUQKBKAc7EQEBAQEBAQEBEAEBAQEHCwsJHzCCHYIGAQEBAwESEQQZARsdAQMBCwYFBAcNKgICIQEBEQEFARwGExsHh3YBAwoIpVKBLz4xi0CBbIJ5iigKGScNVoRZAQEBAQEBBAEBAQEBARYBBQ6LU4JPgjwHgmmBQwWVPYsGgW2BSpFbg1CCHxIjgRcXhCoiM4JNAQEB X-IronPort-AV: E=Sophos;i="5.17,422,1437429600"; d="scan'208";a="143977611" Received: from mail-yk0-f171.google.com ([209.85.160.171]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 27 Aug 2015 16:18:01 +0200 Received: by ykfw73 with SMTP id w73so20958966ykf.3 for ; Thu, 27 Aug 2015 07:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=vtqXEF7EdqlMoBqteN6fOv48QvFTMVeF5Goh7KLn1ko=; b=nWvL6sAAjaXczY6Ag7rdbVRH5c89wfK1YbDI9C6GI9JOizxYgJ1u4X8+B8Wlu1l8Hs YWR4wRdeXOHwaiCsNY2/SR9Zzpd684XDjhMureWtksZtfgCoB2Ag0bGTZVZawA0B8I6j 5Xenw/iotS/WTyhRa/o3au8Q3LqlDZT/obUQu2wC5ZNkeRfC3dCVPP6kyIgha3MXr4nu eJSLGH3Mz8R52wbfBabJfzhu4MQb/kS9vgN+PwR8b8nQ9Jrg2m0hWrBSor2VmF/OVBMI 6zaJVklWK2XV+UgYg57O6PSR7VBufW2RYZBpKH01a6U9tDy8LISO/3DZpFuR7pcSsLqL d30g== X-Received: by 10.129.88.9 with SMTP id m9mr2950032ywb.147.1440685080300; Thu, 27 Aug 2015 07:18:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.37.202.206 with HTTP; Thu, 27 Aug 2015 07:17:40 -0700 (PDT) In-Reply-To: References: From: Yotam Barnoy Date: Thu, 27 Aug 2015 10:17:40 -0400 Message-ID: To: Gabriel Scherer Cc: Ocaml Mailing List Content-Type: multipart/alternative; boundary=001a114936e071d181051e4ba291 Subject: Re: [Caml-list] Expanding functors --001a114936e071d181051e4ba291 Content-Type: text/plain; charset=UTF-8 OK the other option I was hoping for was that I was missing a simple solution, and one was provided, so thank you! On Thu, Aug 27, 2015 at 9:35 AM, Gabriel Scherer wrote: > 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 > 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 > --001a114936e071d181051e4ba291 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
OK the other option I was hoping for was that I was missin= g a simple solution, and one was provided, so thank you!


On Thu, Aug 27,= 2015 at 9:35 AM, Gabriel Scherer <gabriel.scherer@gmail.com&g= t; wrote:
I don't follow. Does= n't

=C2=A0 module MakeBetter (K : sig include Map.OrderedType val show : t ->= ;
string end) =3D
=C2=A0 struct
=C2=A0 =C2=A0 include Map.Make(K)
=C2=A0 =C2=A0 let show show_val m =3D List.show (Pair.show K.show show_val)= (bindings m)
=C2=A0 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 Ordere= dType
> module which contains only the compare function. What happens if I wan= t to
> add something to this interface, such as a show function? I have to co= py the
> whole implementation of Map.Make into my own file to modify it. Compar= e 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 a= s
> needed. Functors are severely lacking in this regard.
>
> What do people think of this idea -- of allowing functors to be expand= ed?
> Ideally, expanding a functor would allow for both replacing its argume= nt
> type (as in the example I gave) and for adding a second/third functor<= br> > argument type (so Map.Make(OrderedType) would become
> Map.Make(OrderedType)(Show).
>
> -Yotam

--001a114936e071d181051e4ba291--