caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Whitington <john@coherentgraphics.co.uk>
To: Nils Becker <nils.becker@bioquant.uni-heidelberg.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] pattern matching on mapped lists
Date: Wed, 03 Jun 2015 17:58:41 +0100	[thread overview]
Message-ID: <556F3241.1050302@coherentgraphics.co.uk> (raw)
In-Reply-To: <556E2CE1.9040801@bioquant.uni-heidelberg.de>

Hi Nils,

Nils Becker wrote:
> I find this syntax handy
>
>      let [ii; jj] = List.map float_of_int [i; j] in
>      ... do stuff with the floats
>
> because it avoids repeating the function call. The compiler lets this
> pass but warns that the matching is not exhaustive since [] is not
> matched. This actually can't happen if I'm not mistaken. So, is this
> considered good style, or is there a better idiomatic way to do multiple
> assignments? If yes, should this be an enhancement request for the type
> checker?

If the lengths are almost always small, why not just put appropriate 
functions map_pair, map_tuple3, map_tuple4 etc. into your library?

fun map_tuple3 f (x, y, z) = (f x, f y, f z)

let (ii, jj) = map_pair float_of_int (i, j)

Or, even...

let ii, jj = map_pair float (i, j)

...if you really want to save typing.

John

-- 
John Whitington
Director, Coherent Graphics Ltd
http://www.coherentpdf.com/


      parent reply	other threads:[~2015-06-03 16:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20150602100015.E87D67EEF7@sympa.inria.fr>
2015-06-02 22:23 ` Nils Becker
2015-06-03 16:52   ` Romain Bardou
2015-06-03 17:42     ` Mikhail Mandrykin
2015-06-03 18:06       ` Octachron
2015-06-03 16:58   ` John Whitington [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=556F3241.1050302@coherentgraphics.co.uk \
    --to=john@coherentgraphics.co.uk \
    --cc=caml-list@inria.fr \
    --cc=nils.becker@bioquant.uni-heidelberg.de \
    /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).