Browse thread
[Caml-list] assertions or exceptions?
-
Radu Grigore
-
Richard Jones
- Daniel Andor
-
Radu Grigore
- Richard Jones
- Jon Harrop
- Brian Hurt
-
Richard Jones
[
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: | Richard Jones <rich@a...> |
| Subject: | Re: [Caml-list] assertions or exceptions? |
On Thu, Jul 15, 2004 at 03:49:19PM +0300, Radu Grigore wrote: > Note that in your example there is always a third choice (the one > advocated by .NET class library design guidelines): do what you do but > also provide a function > > Request.valid_hostname : Request.t -> bool I feel I might be responding to a troll here. It seems to me to be a little obvious that you haven't done much programming OCaml, or else you wouldn't be asking this question. There's an ocaml-beginners list if you'd like to find out more about developing with OCaml. Nevertheless ... let valid_hostname r = try ignore (Request.hostname r); true with Not_found -> false Or, if Request.hostname had been defined the other way, then: let valid_hostname r = match Request.hostname r with None -> false | Some _ -> true In practice you'd never actually write the "valid_hostname" function explicitly, because it's so trivial to inline the code when you need it. > Ok, so I can hide the usage of the exception. It doesn't make me feel > much better. It feels more like redesigning the interface of the > standard library. (but it's a good idea nonetheless). I happen to think that the End_of_file stuff in stdlib *is* quite clunky. However since my main usage of files is "open file; read entire contents into list of lines; close file", or "open file; write this list of lines; close file", and I now have my own functions which do both those operations in a single call, it doesn't bother me much. Rich. -- Richard Jones. http://www.annexia.org/ http://www.j-london.com/ Merjis Ltd. http://www.merjis.com/ - improving website return on investment MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles, RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/ ------------------- 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