Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] assertions or exceptions?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-15 (13:34)
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

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


Richard Jones.
Merjis Ltd. - improving website return on investment
MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles,
RPMs, pkgs etc. Linux, BSD, Solaris.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: