From: Yitzhak Mandelbaum <yitzhakm@CS.Princeton.EDU>
To: OCaml mailing list <caml-list@inria.fr>
Subject: Re: [Caml-list] optional functions in modules
Date: Thu, 17 May 2012 13:43:53 -0400 [thread overview]
Message-ID: <BC84E0A3-D1C6-4258-BAAF-2911B119781A@cs.princeton.edu> (raw)
In-Reply-To: <CACLX4jSVwAdwAMikg1tDQJcE_cRXixGQdNL0adAMcdct3LCrgg@mail.gmail.com>
Thanks to everyone who responded. FWIW, I found the argument in favor of options most compelling as a general approach.
Yitzhak
On May 10, 2012, at 8:55 PM, Yaron Minsky wrote:
> Core's approach to this is to use options. (Technically, we use a
> type called Or_error.t, which has a useful error message in the
> error-variant, but it's the same idea.)
>
> On Thu, May 10, 2012 at 2:44 PM, Goswin von Brederlow <goswin-v-b@web.de> wrote:
>> Yitzhak Mandelbaum <yitzhakm@cs.princeton.edu> writes:
>>
>>> Hi,
>>>
>>> Is there any "common wisdom" regarding the inclusion of optional functions in a module signature? The two most obvious approaches involve 1) a pair of boolean flag and a function, where the function raises an exception if unimplemented OR 2) using the option type. I see pros/cons to each approach, but am curious if there's any (unofficial) standard approach.
>>>
>>> Yitzhak
>>> -----------------------------
>>> Yitzhak Mandelbaum
>>
>> The extunix module has a trifold solution for this:
>>
>> * First there is the ExtUnix.All module that has all functions in
>> it. Functions that are not available raise Not_available with function
>> name as an argument.
>>
>> * Second there is ExtUnix.All.have : string -> bool option
>>
>> (** [have name]
>> @return indication whether function [name] is available
>> - [Some true] if available
>> - [Some false] if not available
>> - [None] if not known
>>
>> e.g. [have "eventfd"]
>> *)
>>
>> * Third there is ExtUnix.Specific containing only functions available on
>> this platform.
>>
>> MfG
>> Goswin
>>
>> --
>> Caml-list mailing list. Subscription management and archives:
>> https://sympa-roc.inria.fr/wws/info/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>>
>
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
-----------------------------
Yitzhak Mandelbaum
next prev parent reply other threads:[~2012-05-17 17:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-10 12:22 Yitzhak Mandelbaum
2012-05-10 14:13 ` "Markus W. Weißmann"
2012-05-10 14:53 ` Fabrice Le Fessant
2012-05-10 14:59 ` David Rajchenbach-Teller
2012-05-10 18:44 ` Goswin von Brederlow
2012-05-11 0:55 ` Yaron Minsky
2012-05-17 17:43 ` Yitzhak Mandelbaum [this message]
2012-05-18 15:24 ` David Rajchenbach-Teller
2012-05-18 16:00 ` Gabriel Scherer
2012-05-18 20:05 ` Nicolas Braud-Santoni
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=BC84E0A3-D1C6-4258-BAAF-2911B119781A@cs.princeton.edu \
--to=yitzhakm@cs.princeton.edu \
--cc=caml-list@inria.fr \
/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