Browse thread
[Caml-list] Facing syntax error.
-
Bhavik Gandhi (hotmail)
- Matt Gushee
- Stefano Zacchiroli
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Matt Gushee <matt@g...> |
| Subject: | Re: [Caml-list] Facing syntax error. |
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