From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p41JWOxD006604 for ; Sun, 1 May 2011 21:32:24 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqwBABy0vU3RVdK2mGdsb2JhbACYVY0/CBQBAQEBAQgJDQcUJadginyCKoNQNIheAQEDBoV6BI55hBmBDoUTO4NJ X-IronPort-AV: E=Sophos;i="4.64,298,1301868000"; d="scan'208";a="107181759" Received: from mail-iy0-f182.google.com ([209.85.210.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 01 May 2011 21:32:23 +0200 Received: by iyj12 with SMTP id 12so7814485iyj.27 for ; Sun, 01 May 2011 12:32:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=zjRM8CakDQBxexqOKAuo8cWRFmYM/Hw7rstWbCLsph0=; b=uGzvQOLCSkhXZk6khXZJ2TK9uFvu53bK8Mm/m+7zBqRElSAzJKzThta8N/sOFHlexb ePuE/jv03yKA1kGthBP7ikW/0mQbLd0jHvLBBTJfjPDHemOcaSwEVjhnslf3NGwiUTph C9NDli8Y5eI8lj0H5apwshrw1hxZWpuCOLibc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=ey5OFSfCWv6wWG6Ts3PtizGd2JP2fW5AonfvUTL42sYGNTA1EGYBoUg0slg/SYcYs4 e/lmT1j0aZg426XxqO0Jpkik+jU3ZKwSaWt5ku0bLt3YEzBEUJza9aZ0InTP3/onUyz0 tC6tB4jhIUL6+QAmt+6VfxMMCTIypMg9hvCNM= Received: by 10.42.131.196 with SMTP id a4mr4717889ict.345.1304278342469; Sun, 01 May 2011 12:32:22 -0700 (PDT) Received: from [192.168.1.65] (99-121-78-10.lightspeed.lnngmi.sbcglobal.net [99.121.78.10]) by mx.google.com with ESMTPS id gy41sm2041658ibb.56.2011.05.01.12.32.20 (version=SSLv3 cipher=OTHER); Sun, 01 May 2011 12:32:21 -0700 (PDT) Message-ID: <4DBDB543.7070603@gmail.com> Date: Sun, 01 May 2011 15:32:19 -0400 From: Edgar Friendly User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110419 Thunderbird/3.1.9 MIME-Version: 1.0 To: caml-list@inria.fr References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Polymorphism question On 05/01/2011 02:07 PM, Sen Horak wrote: > Hi, > > I am trying to model a situation in which a caller calls a combination > of two functions: > let res_a = f inp_c inp_d in my_g res_a > > But it would be nice to hide 'a' from the caller and have her call: > let res_b = f inp_c inp_d my_g > > I guess I could use functors, and configure a generic f with a > particular type of g. Does that seem right, and if so could there be a > simper or easier way? Yes: let f_simplified inp_c inp_d my_g = let res_a = f inp_c inp_d in my_g res_a If you want, you can inline f_simplified into the original f, or use some sugar notation included in both batteries and core as: let f_simplified c d g = f c d |> g This is a straightforward application of higher order functions, where the function g is taken as a parameter of f_simplified and called from inside it. The type of f_simplified is 'c -> 'd -> ('a -> 'b) -> 'b, showing the third parameter (g) has type ('a -> 'b). If I were designing this, I'd have the caller use |> to convert the output instead of putting this in your function. E.