From: Oliver Bandel <oliver@first.in-berlin.de>
To: John Max Skaller <skaller@ozemail.com.au>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Some/None
Date: Wed, 24 Apr 2002 18:49:19 +0200 (MET DST) [thread overview]
Message-ID: <Pine.LNX.3.95.1020424183916.3286B-100000@first.in-berlin.de> (raw)
In-Reply-To: <3CC6C76B.4050408@ozemail.com.au>
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
next prev parent reply other threads:[~2002-04-24 16:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-24 12:48 Oliver Bandel
2002-04-24 13:31 ` Michal Moskal
2002-04-24 14:23 ` Oliver Bandel
2002-04-24 15:43 ` Samuel Lacas
2002-04-24 13:41 ` Markus Mottl
2002-04-24 15:59 ` Oliver Bandel
2002-04-24 13:50 ` Oliver Bandel
2002-04-24 14:08 ` Xavier Leroy
2002-04-24 19:19 ` Oliver Bandel
2002-04-24 14:28 ` Remi VANICAT
2002-04-24 14:55 ` John Max Skaller
2002-04-24 16:49 ` Oliver Bandel [this message]
2002-04-25 1:46 ` John Max Skaller
2002-04-25 12:13 ` Oliver Bandel
2002-04-25 12:34 ` Markus Mottl
2002-04-25 12:53 ` Jérôme Marant
2002-04-25 13:13 ` Markus Mottl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.3.95.1020424183916.3286B-100000@first.in-berlin.de \
--to=oliver@first.in-berlin.de \
--cc=caml-list@inria.fr \
--cc=skaller@ozemail.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox