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 QAA23660; Wed, 24 Apr 2002 16:55:52 +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 QAA23645 for ; Wed, 24 Apr 2002 16:55:51 +0200 (MET DST) Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.25.148.40]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3OEtm116839 for ; Wed, 24 Apr 2002 16:55:49 +0200 (MET DST) Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id g3OEteXt009001; Thu, 25 Apr 2002 00:55:40 +1000 (EST) Received: from ozemail.com.au (ppp171.dyn20.pacific.net.au [61.8.20.171]) by wisma.pacific.net.au with ESMTP id AAA13281; Thu, 25 Apr 2002 00:55:38 +1000 (EST) Message-ID: <3CC6C76B.4050408@ozemail.com.au> Date: Thu, 25 Apr 2002 00:55:39 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: Oliver Bandel CC: caml-list@inria.fr Subject: Re: [Caml-list] Some/None References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 let lst = [1;2;3;4] let pos lst x = let pos lst n = match lst with | h :: t -> if h = x then Some n else pos t (n+1) | [] -> None in pos lst 0 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. >(e.g. is_regularfile/is_directory/...) > What you want here is: type file_type_t = Regular | Directory | Special | Root | NonExistant let file_type (s:string): file_type_t = (code to find the file type here) ... This function finds the type of the file and returns it, I include the case the file is non-existant. This is exactly a C enumeration. Only you can have arguments. For example, an extended file function might use the construction type file_data = | Regular of int (* file size in megs *) | Directory of int (* number of entries *) | Special .... This is a union of cases, just like an enumeration, only now some extra data is tacked on to some of the cases. -- John Max Skaller, mailto:skaller@ozemail.com.au snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 ------------------- 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