Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Function forward declaration?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Function forward declaration?
On Thu, Apr 08, 2004 at 01:51:21AM +1000, skaller wrote:
> > (Same, by the way, goes for a 'return' statement which OCaml is crying
> > out for).
> 
> I don't think it makes any sense in Ocaml.
[...]

This is the sort of thing which I'd like to write.  Note not only the
return statement, but also the regular expression support:

let run dbh q userid =
  if check_permissions userid = Failed then (
    StdPages.error q "Sorry, but you don't have permission to see this";
    return
  );

  let query = q#param "query" in

  if query =~ /^\s*$/ then (
    StdPages.error q "Please enter a query";
    return
  );

  let resource =
    try find_resource dbh query
    with
      Not_found ->
	StdPages.error q "That resource doesn't exist in the database";
        return
    in

  (* Do lots and lots of real processing here. *)


  StdPages.ok q "OK, your query was executed"

-----

That's pseudocode of course, and I'm not saying that it isn't possible
to do this in OCaml already using exceptions, but doing so is very
clumsy compared to having a return statement (and indeed regular
expression support).

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
'There is a joke about American engineers and French engineers. The
American team brings a prototype to the French team. The French team's
response is: "Well, it works fine in practice; but how will it hold up
in theory?"'

-------------------
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