From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA25490; Wed, 15 Oct 2003 01:38:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA19237 for ; Wed, 15 Oct 2003 01:38:09 +0200 (MET DST) Received: from mz1.forethought.net (mzpi3.forethought.net [216.241.36.12]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h9ENc6100974 for ; Wed, 15 Oct 2003 01:38:08 +0200 (MET DST) Received: from [216.241.35.41] (helo=swordfish) by mz1.forethought.net with esmtp (Exim 4.14) id 1A9Yjs-00026i-Qx for caml-list@pauillac.inria.fr; Tue, 14 Oct 2003 17:38:04 -0600 Received: from matt by swordfish with local (Exim 3.35 #1 (Debian)) id 1A9Yk0-00074W-00 for ; Tue, 14 Oct 2003 17:38:12 -0600 Date: Tue, 14 Oct 2003 17:38:11 -0600 From: Matt Gushee To: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] Facing syntax error. Message-ID: <20031014233811.GA26799@swordfish> Reply-To: Matt Gushee Mail-Followup-To: caml-list@pauillac.inria.fr References: <000401c392c6$e9c5a550$0900a8c0@maverick> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000401c392c6$e9c5a550$0900a8c0@maverick> User-Agent: Mutt/1.3.27i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; gushee:01 gushee:01 caml-list:01 endline:01 englewood:01 manure:01 mgushee:01 havenrock:01 havenrock:01 ignores:01 --lao:01 merel:01 ocaml:01 handler:01 rec:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, Oct 14, 2003 at 06:49:11PM -0800, Bhavik Gandhi (hotmail) wrote: > > I am a novice to the OCAML language. I am trying to write a small > program and I am facing with a syntax error, any help will be > appreciated > > let rec undup lst = try match lst with > |[]->[] > |h::tail -> match tail with > |[]->[] > |h::xt -> if (h=List.hd xt) then h::undup xt > else raise(Failure "ERROR-Your list does not contain duplicates");; > > Error: line 6, characters 67-69 > Syntax error. Right, because you have 'try' without 'with'. The syntax is try with -> | -> (* 2nd & further patterns are optional *) You could make the above example work by adding a 'with' clause at the end, e.g. with Failure -> 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