Re: Newbies question

From: Xavier Leroy (Xavier.Leroy@inria.fr)
Date: Mon Oct 04 1999 - 15:37:06 MET DST


Date: Mon, 4 Oct 1999 15:37:06 +0200
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Peter Bruhn <bruhn@isis.wu-wien.ac.at>, caml-list@inria.fr
Subject: Re: Newbies question
In-Reply-To: <Pine.LNX.4.05.9910011500140.16555-100000@lux1.wu-wien.ac.at>; from Peter Bruhn on Fri, Oct 01, 1999 at 03:01:28PM +0200

> The following function does not compile, since the compiler thinks it has
> the wrong return type:

You've already received plenty of explanations on what's going on.
Let me just add one easy way to work around this: just have your "try"
construct return () in all cases. Like this:

> let read_res file : ('a * 'b) list =
> let final_result = ref [] in
> let fd = open_in file in
> begin try
> let lexbuf = Lexing.from_channel fd in
> while true do
> let result = Parseres.main Lexres.token lexbuf in
> final_result := result :: !final_result
> done
> with
> Lexres.Eof -> () (* this is the "normal" loop exit *)
> | Parsing.Parse_error ->
> close_in fd; printf "ERROR: Ressourcen Datei fehlerhaft\n";
> exit (-1)
> end;
> close_in fd; !final_result

- Xavier Leroy



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:25 MET