caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: oliver <oliver@first.in-berlin.de>
To: Martin DeMello <martindemello@gmail.com>
Cc: OCaml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] is there a more concise way to write this?
Date: Fri, 20 Jan 2012 10:38:34 +0100	[thread overview]
Message-ID: <20120120093834.GB1870@siouxsie> (raw)
In-Reply-To: <CAFrFfuEk3-Y7Gd4aSp7-xXWyceaBZCVtWUKg9AD8DoZXgTVEoA@mail.gmail.com>

Hello,

On Thu, Jan 19, 2012 at 10:38:53PM -0800, Martin DeMello wrote:
>       let a = match (out, value) with
>         (true, true)  -> [o; v]
>       | (false, true) -> [v]
>       | (true, false) -> [o]
>       | (false, false) -> []

The code looks fine for me.

More concise does not always mean better readable or more performant.
You apply the same kind of selection for both values.

Something that would aequivalent would be of type 'a option.
But I doubt that using option type here would make it more concise.

Would it make it Better readable? Not necessarily.

But at least it would show the operation more clear.

But not sure if you want to handle option type in your result.

I think a fold could do the selection of the raw values afterwards.

If out is derived from o and v is derived from v and both are selected
by the same function, you could use that function inside a fold.
But would that really be more readable?
It might be more generic.
But if both selections are not done by the same function application to your
result values, this also does not make sense.

Do you see what I mean?

Ciao,
   Oliver

  parent reply	other threads:[~2012-01-20  9:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-20  6:38 Martin DeMello
2012-01-20  6:46 ` Valentin ROBERT
2012-01-20  6:58   ` Martin DeMello
2012-01-20  8:37   ` David Allsopp
2012-01-20 13:29     ` Edgar Friendly
2012-01-20 13:50       ` Fabrice Le Fessant
2012-01-20 13:58       ` oliver
2012-01-20 14:05         ` Edgar Friendly
2012-01-20 14:12       ` David Allsopp
2012-01-20 14:23         ` Fabrice Le Fessant
2012-01-20 14:23         ` Edgar Friendly
2012-01-20  8:37   ` Sebastien Ferre
2012-01-20  9:11     ` Jerome Vouillon
2012-01-20  9:34       ` Fabrice Le Fessant
2012-01-20 10:27         ` Arnaud Spiwack
2012-01-20  8:52 ` Lin
2012-01-20  9:08   ` Valentin ROBERT
2012-01-20  9:19     ` Lin
2012-01-20 10:21     ` Martin DeMello
2012-01-20  9:38 ` oliver [this message]
2012-01-20 13:59   ` Edgar Friendly
2012-01-20 14:42     ` oliver
2012-01-20 15:31     ` Fabrice Le Fessant
2012-01-20 21:04     ` oliver
2012-01-20 21:09       ` oliver
2012-01-20 20:40 ` oliver
2012-01-20 21:07   ` Martin DeMello

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=20120120093834.GB1870@siouxsie \
    --to=oliver@first.in-berlin.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=martindemello@gmail.com \
    /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).