<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/11/c5e9aace0d2e0cee5765b5fd98eb520d"
  from="Aleksey Nogin &lt;nogin@c...&gt;"
  author="Aleksey Nogin"
  date="2003-11-18T00:40:57"
  subject="Re: [Caml-list] Records: syntax error..."
  prev="2003/11/4d893cc52b22fe3904f8f579fcf78b2d"
  next="2003/11/6da311da670a99572f6a1091fd48e228"
  prev-in-thread="2003/11/4d893cc52b22fe3904f8f579fcf78b2d"
  next-in-thread="2003/11/eb05995e3d523b2303ba34dba1bbf2c3"
  prev-thread="2003/11/398e682363175b0a71bf952390df0eae"
  next-thread="2003/11/6da311da670a99572f6a1091fd48e228"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Records: syntax error...">
<msg 
  url="2003/11/4d893cc52b22fe3904f8f579fcf78b2d"
  from="chris.danx &lt;chris.danx@n...&gt;"
  author="chris.danx"
  date="2003-11-18T00:18:22"
  subject="[Caml-list] Records: syntax error...">
<msg 
  url="2003/11/c5e9aace0d2e0cee5765b5fd98eb520d"
  from="Aleksey Nogin &lt;nogin@c...&gt;"
  author="Aleksey Nogin"
  date="2003-11-18T00:40:57"
  subject="Re: [Caml-list] Records: syntax error...">
<msg 
  url="2003/11/eb05995e3d523b2303ba34dba1bbf2c3"
  from="chris.danx &lt;chris.danx@n...&gt;"
  author="chris.danx"
  date="2003-11-18T14:31:08"
  subject="Re: [Caml-list] Records: syntax error...">
</msg>
</msg>
</msg>
</thread>

<contents>
On 17.11.2003 16:23, chris.danx wrote:

&gt; let insert item dl =
&gt;   match dl with
&gt;       {l = _; compare = _; in_order = true}  -&gt;

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 } -&gt; ...

&gt;               {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]) }

&gt;     | {l = _; compare = _; in_order = false} -&gt;
&gt;               {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

</contents>

</message>

