* Re: [Caml-list] Facing syntax error.
2003-10-15 2:49 [Caml-list] Facing syntax error Bhavik Gandhi (hotmail)
@ 2003-10-14 23:38 ` Matt Gushee
2003-10-15 7:51 ` Stefano Zacchiroli
1 sibling, 0 replies; 3+ messages in thread
From: Matt Gushee @ 2003-10-14 23:38 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Caml-list] Facing syntax error.
@ 2003-10-15 2:49 Bhavik Gandhi (hotmail)
2003-10-14 23:38 ` Matt Gushee
2003-10-15 7:51 ` Stefano Zacchiroli
0 siblings, 2 replies; 3+ messages in thread
From: Bhavik Gandhi (hotmail) @ 2003-10-15 2:49 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 428 bytes --]
Hi friends,
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.
Bhavik Gandhi
[-- Attachment #2: Type: text/html, Size: 5914 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Facing syntax error.
2003-10-15 2:49 [Caml-list] Facing syntax error Bhavik Gandhi (hotmail)
2003-10-14 23:38 ` Matt Gushee
@ 2003-10-15 7:51 ` Stefano Zacchiroli
1 sibling, 0 replies; 3+ messages in thread
From: Stefano Zacchiroli @ 2003-10-15 7:51 UTC (permalink / raw)
To: caml-list
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
Please use the beginners list for this kind of questions:
http://groups.yahoo.com/group/ocaml_beginners
Cheers.
--
Stefano Zacchiroli -- Master in Computer Science @ Uni. Bologna, Italy
zack@{cs.unibo.it,debian.org,bononia.it} - http://www.bononia.it/zack/
" I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant! " -- G.Romney
-------------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-10-15 7:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-15 2:49 [Caml-list] Facing syntax error Bhavik Gandhi (hotmail)
2003-10-14 23:38 ` Matt Gushee
2003-10-15 7:51 ` Stefano Zacchiroli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox