Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Edgar Friendly <thelema314@gmail.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Polymorphism question
Date: Sun, 01 May 2011 15:32:19 -0400	[thread overview]
Message-ID: <4DBDB543.7070603@gmail.com> (raw)
In-Reply-To: <BANLkTi=RYfNLxH+0VWZB1_UUsLKJAmjNuw@mail.gmail.com>

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.

      reply	other threads:[~2011-05-01 19:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-01 18:07 Sen Horak
2011-05-01 19:32 ` Edgar Friendly [this message]

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=4DBDB543.7070603@gmail.com \
    --to=thelema314@gmail.com \
    --cc=caml-list@inria.fr \
    /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