From: David Rajchenbach-Teller <David.Teller@ens-lyon.org>
To: Fabrice Le Fessant <fabrice@lefessant.net>
Cc: Yitzhak Mandelbaum <yitzhakm@cs.princeton.edu>,
OCaml mailing list <caml-list@inria.fr>
Subject: Re: [Caml-list] optional functions in modules
Date: Thu, 10 May 2012 16:59:54 +0200 [thread overview]
Message-ID: <4FABD7EA.7080902@ens-lyon.org> (raw)
In-Reply-To: <CAHvkLrNC5256HXxxvX8yNjSzy0cXST5xr-M_km6JrXhNhF+_+g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 977 bytes --]
I would personally use an [option] and a form of startup-time
configuration, quite comparable to the browser-feature detection in
JavaScript.
So, something like
let my_function = match Module.may_have_feature with
| Some implementation -> implementation
| None -> (*either a workaround or an error*)
Cheers,
David
On 5/10/12 4:53 PM, Fabrice Le Fessant wrote:
> I would say that it depends on how likely it is that somebody is going
> to handle the case where the function is not implemented. I would use
> a boolean to detect if the function is implemented, and calling the
> missing function would raise an exception (be careful to define the
> corresponding exception, using failwith "not implemented" might be too
> generic to be useful, although I always do it in my programs ;-) ). If
> it is highly likely that the program is going to handle the missing
> function, using a Some type for the function is better idea.
>
> -Fabrice
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
next prev parent reply other threads:[~2012-05-10 15:00 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 [this message]
2012-05-10 18:44 ` Goswin von Brederlow
2012-05-11 0:55 ` Yaron Minsky
2012-05-17 17:43 ` Yitzhak Mandelbaum
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=4FABD7EA.7080902@ens-lyon.org \
--to=david.teller@ens-lyon.org \
--cc=caml-list@inria.fr \
--cc=fabrice@lefessant.net \
--cc=yitzhakm@cs.princeton.edu \
/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