From: Aleksey Nogin <nogin@cs.caltech.edu>
To: "chris.danx" <chris.danx@ntlworld.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Records: syntax error...
Date: Mon, 17 Nov 2003 16:40:49 -0800 [thread overview]
Message-ID: <3FB96A91.8000108@cs.caltech.edu> (raw)
In-Reply-To: <3FB9668D.3060709@ntlworld.com>
On 17.11.2003 16:23, chris.danx wrote:
> let insert item dl =
> match dl with
> {l = _; compare = _; in_order = true} ->
Hint: you do not have to mention the fiends that you are not interested in.
So you could just use
... match dl with
{ in_order = true } -> ...
> {merge dl.compare (dl.l, [item]), dl.compare, true}
You have to use the explicit field names when you construct records:
{ l = merge dl.compare (dl.l, [item]);
compare = dl.compare;
in_order = true
}
Hint: if you want to create a new record that only slightly differs from
an existing one, use the "with" construction:
{ dl with l = merge dl.compare (dl.l, [item]) }
> | {l = _; compare = _; in_order = false} ->
> {item::dl.l, dl.compare, false};;
Hint: it is IMHO a bad style to use "match" expressions simply to check
on a boolean value - it's much more intuitive to use "if/then/else" for
that.
P.S. Here is how I would have written the insert function above:
let insert item dl =
{ dl with l =
if dl.in_order then
merge dl.compare (dl.l, [item])
else
item::dl.l
}
--
Aleksey Nogin
Home Page: http://nogin.org/
E-Mail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal)
Office: Jorgensen 70, tel: (626) 395-2907
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2003-11-18 0:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-18 0:23 chris.danx
2003-11-18 0:40 ` Aleksey Nogin [this message]
2003-11-18 14:36 ` chris.danx
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=3FB96A91.8000108@cs.caltech.edu \
--to=nogin@cs.caltech.edu \
--cc=caml-list@inria.fr \
--cc=chris.danx@ntlworld.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).