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 3D1C97F7C2 for ; Wed, 5 Feb 2014 20:43:11 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of martin.jambon@ens-lyon.org) identity=pra; client-ip=66.111.4.28; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="martin.jambon@ens-lyon.org"; x-sender="martin.jambon@ens-lyon.org"; x-conformance=sidf_compatible Received-SPF: Neutral (mail3-smtp-sop.national.inria.fr: domain of martin.jambon@ens-lyon.org does not assert whether or not 66.111.4.28 is permitted sender) identity=mailfrom; client-ip=66.111.4.28; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="martin.jambon@ens-lyon.org"; x-sender="martin.jambon@ens-lyon.org"; 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@out4-smtp.messagingengine.com) identity=helo; client-ip=66.111.4.28; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="martin.jambon@ens-lyon.org"; x-sender="postmaster@out4-smtp.messagingengine.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApkBABCT8lJCbwQcm2dsb2JhbABZhxy7S4EQFg4BAQEBAQYLCwkUKIIlAQEEASMEEQgrDQEBBAsLGAICBRYLAgIJAwIBAgFFBg0BBwEBh3kIrFh2g2KdVhEGgSmNTAeCb4FJAYlMlSqPJw X-IPAS-Result: ApkBABCT8lJCbwQcm2dsb2JhbABZhxy7S4EQFg4BAQEBAQYLCwkUKIIlAQEEASMEEQgrDQEBBAsLGAICBRYLAgIJAwIBAgFFBg0BBwEBh3kIrFh2g2KdVhEGgSmNTAeCb4FJAYlMlSqPJw X-IronPort-AV: E=Sophos;i="4.95,788,1384297200"; d="scan'208";a="47937337" Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 05 Feb 2014 20:43:10 +0100 Received: from compute6.internal (compute6.nyi.mail.srv.osa [10.202.2.46]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 6DF72209D1; Wed, 5 Feb 2014 14:43:08 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Wed, 05 Feb 2014 14:43:08 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=dq8vAMFIvr5eJbrSIEw9C2 136Qw=; b=SLGAeZmHauVW0Jfs2mcbgAvGmqvagNcbvSwG3clisSyl9DGahj0aan GLzryXE/TV+VTEqsu7ATPMITynaCKktgwBNGJy0xtPOsTn5+/cr4vR3xwEaRylQR ZG16juXx9L0VwlZc6k7zRYHCMsIIUPgwp8TupjPP2xIGenyRBVv+o= X-Sasl-enc: anmtb138LzemgVw77KcnX0Kmt7ZTV1MyG9mNyPQL8LtQ 1391629388 Received: from [172.16.71.72] (unknown [50.193.45.145]) by mail.messagingengine.com (Postfix) with ESMTPA id EBFDD680092; Wed, 5 Feb 2014 14:43:07 -0500 (EST) Message-ID: <52F2944A.3000908@ens-lyon.org> Date: Wed, 05 Feb 2014 11:43:06 -0800 From: Martin Jambon User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: Yotam Barnoy CC: Ocaml Mailing List References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Default methods for module signatures On Wed 05 Feb 2014 10:49:29 AM PST, Yotam Barnoy wrote: > Hello List > > I would like the following feature, and I'm not enough of an expert in > module-fu to know if something like this is doable. > > Suppose I have a module signature of > > module type Monad = sig > type 'a m > val return : 'a -> 'a m > val (>>=) : 'a m -> ('a -> 'b m) -> 'b m > val (>>) : 'a m -> 'b m -> 'b m > end > > I would like to have a default implementation for (>>), since a simple > default implementation is > > let (>>) m f = m >>= fun _ -> f > > Alternatively, I would like to include this from some DefaultMonad > module, but have the (>>=) referred to in the function be my newly > defined (>>=) implementation (ie. late binding). Is there currently > any way to do this? If not, would there be a way to implement a > partial default implementation built into or associated with a module > signature? Something like OCaml has functors but they don't support optional fields in their arguments. You can create a functor Monad.Make that takes a module without (>>) and creates a module with an extra (>>) field. However, if the input module contains (>>) already, the new implementation will override it as in this minimal example: # module A = struct end;; module A : sig end # module M(A: module type of A) = struct include A let x = 0 end;; module M : functor (A : sig end) -> sig val x : int end # module B = M(struct end);; module B : sig val x : int end # module C = M(struct let x = 1 end);; module C : sig val x : int end # C.x;; - : int = 0 C.x is 0, not 1. There may be clever tricks to support some kind of optional module field pattern, though. I'll let others scratch their heads. :-) > module type Monad = sig... default struct... end > > Haskell has this available as part of the semantics of their typeclass > system, and I think it would be really handy to have (if there isn't > already a way to do it currently). > > -Yotam > >