From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA26328; Wed, 24 Apr 2002 18:52:40 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA26367 for ; Wed, 24 Apr 2002 18:52:39 +0200 (MET DST) Received: from hirsch.in-berlin.de (hirsch.in-berlin.de [192.109.42.6]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3OGqc119374 for ; Wed, 24 Apr 2002 18:52:38 +0200 (MET DST) Received: from hirsch.in-berlin.de (localhost [127.0.0.1]) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with ESMTP id g3OGqbTL011831 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT); Wed, 24 Apr 2002 18:52:37 +0200 Received: (from uucp@localhost) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with UUCP id g3OGqa6Y011829; Wed, 24 Apr 2002 18:52:36 +0200 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: caml-list@inria.fr Received: from localhost (oliver@localhost) by first.in-berlin.de (8.7.6/8.7.3) with SMTP id SAA03585; Wed, 24 Apr 2002 18:49:19 +0200 Date: Wed, 24 Apr 2002 18:49:19 +0200 (MET DST) From: Oliver Bandel To: John Max Skaller cc: caml-list@inria.fr Subject: Re: [Caml-list] Some/None In-Reply-To: <3CC6C76B.4050408@ozemail.com.au> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 25 Apr 2002, John Max Skaller wrote: > Oliver Bandel wrote: > > >Does it make sense to give back None/Some > >out of a function > > > Oh yes! I do this all the time, lots and lots. > > Consider > [...] > which searches a list for a number x, > and returns its position n as > > Some n > > if it is found in the list, or > > None > > if it isn't: its position in the list is None, > it doesn'tr have a position, or Some position > if it does. OK, that makes sense to me. :) > > >(e.g. is_regularfile/is_directory/...) > > > > What you want here is: > > type file_type_t = Regular | Directory | Special | Root | NonExistant Wow! Good idea. So I don't rely on the predefined type and use my own :) That's fine. > > let file_type (s:string): file_type_t = > > (code to find the file type here) ... OK :) let type_of_file (name:string) = try ( match (Unix.stat name).Unix.st_kind with | Unix.S_REG -> Regular | Unix.S_DIR -> Directory | Unix.S_CHR -> Special | Unix.S_BLK -> Special | Unix.S_LNK -> Special (* ok, on ENOENT Unix.lstat *) | Unix.S_FIFO -> Special | Unix.S_SOCK -> Special ) with | Unix.Unix_error (Unix.ENOENT,_,_) -> NonExistant (* maybe link-problem => Unix.lstat *) So this makes completely sense. [...] > type file_data = > | Regular of int (* file size in megs *) > | Directory of int (* number of entries *) > | Special > .... nice idea. :) Thanks, Oliver ------------------- 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