caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Matt Gushee <matt@gushee.net>
To: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] Facing syntax error.
Date: Tue, 14 Oct 2003 17:38:11 -0600	[thread overview]
Message-ID: <20031014233811.GA26799@swordfish> (raw)
In-Reply-To: <000401c392c6$e9c5a550$0900a8c0@maverick>

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
    <desired operations>
  with
    <exception pattern> ->
      <exception handling code>
    | <exception pattern> -> (* 2nd & further patterns are optional *)
      <exception handling code>
    
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


  reply	other threads:[~2003-10-14 23:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-15  2:49 Bhavik Gandhi (hotmail)
2003-10-14 23:38 ` Matt Gushee [this message]
2003-10-15  7:51 ` Stefano Zacchiroli

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=20031014233811.GA26799@swordfish \
    --to=matt@gushee.net \
    --cc=caml-list@pauillac.inria.fr \
    /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).