<?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/10/94157d29f1220115827324f5a29e1d61"
  from="Matt Gushee &lt;matt@g...&gt;"
  author="Matt Gushee"
  date="2003-10-14T23:38:11"
  subject="Re: [Caml-list] Facing syntax error."
  prev="2003/10/3557909eb406de5c9c556ee445b3095e"
  next="2003/10/22b8f0ac4fb38072f78facd4bf9434a7"
  prev-in-thread="2003/10/3557909eb406de5c9c556ee445b3095e"
  next-in-thread="2003/10/40efc6d7a09a9588ce9fc3fe42b29f4e"
  prev-thread="2003/10/9235eab2ffb969edc09cc15e9dfea256"
  next-thread="2003/10/0c272dd5bfb35ce29fe72630db24b26f"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Facing syntax error.">
<msg 
  url="2003/10/3557909eb406de5c9c556ee445b3095e"
  from="Bhavik Gandhi (hotmail) &lt;bhavik_gandhi@h...&gt;"
  author="Bhavik Gandhi (hotmail)"
  date="2003-10-14T22:47:27"
  subject="[Caml-list] Facing syntax error.">
<msg 
  url="2003/10/94157d29f1220115827324f5a29e1d61"
  from="Matt Gushee &lt;matt@g...&gt;"
  author="Matt Gushee"
  date="2003-10-14T23:38:11"
  subject="Re: [Caml-list] Facing syntax error.">
</msg>
<msg 
  url="2003/10/40efc6d7a09a9588ce9fc3fe42b29f4e"
  from="Stefano Zacchiroli &lt;zack@b...&gt;"
  author="Stefano Zacchiroli"
  date="2003-10-15T07:51:13"
  subject="Re: [Caml-list] Facing syntax error.">
</msg>
</msg>
</thread>

<contents>
On Tue, Oct 14, 2003 at 06:49:11PM -0800, Bhavik Gandhi (hotmail) wrote:
&gt;  
&gt; I am a novice to the OCAML language. I am trying to write a small
&gt; program and I am facing with a syntax error, any help will be
&gt; appreciated
&gt;  
&gt; let rec undup lst = try match lst with
&gt;   |[]-&gt;[]
&gt;   |h::tail -&gt; match tail with
&gt;   |[]-&gt;[]
&gt;   |h::xt -&gt; if (h=List.hd xt) then h::undup xt
&gt;   else raise(Failure "ERROR-Your list does not contain duplicates");;
&gt;  
&gt; Error: line 6, characters 67-69
&gt; Syntax error.

Right, because you have 'try' without 'with'. The syntax is

  try
    &lt;desired operations&gt;
  with
    &lt;exception pattern&gt; -&gt;
      &lt;exception handling code&gt;
    | &lt;exception pattern&gt; -&gt; (* 2nd &amp; further patterns are optional *)
      &lt;exception handling code&gt;
    
You could make the above example work by adding a 'with' clause at the
end, e.g.

  with Failure -&gt;
    print_endline "Exception handled.";
    []   (* exception handler must return same type as main operation *)

But that would actually be a little pointless in this case, since as far
as I can tell the only possible exception is the Failure raised by your
code. So without knowing your objectives in more detail, I would say the
most sensible approach would be to simply delete 'try' from this
function, and perhaps have a complete try-with block in some other
function that is calling this one.


-- 
Matt Gushee                 When a nation follows the Way,
Englewood, Colorado, USA    Horses bear manure through
mgushee@havenrock.com           its fields;
http://www.havenrock.com/   When a nation ignores the Way,
                            Horses bear soldiers through
                                its streets.
                                
                            --Lao Tzu (Peter Merel, trans.)

-------------------
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>

