From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 49BE67ED1A for ; Thu, 17 May 2012 19:43:55 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: At8CAM83tU+AcIhIe2dsb2JhbABEoTuSDSIBARYmBSKCFQEBAQMBJ0cQCwsYDSFFEgYTEgmHZQMGBQuyFQMfNYkJixOEdWIDlwuSNA X-IronPort-AV: E=Sophos;i="4.75,611,1330902000"; d="scan'208";a="158814957" Received: from redflag.cs.princeton.edu ([128.112.136.72]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 May 2012 19:43:54 +0200 Received: from sslvpn-96-85.sei.cmu.edu (vpn-nat-159.sei.cmu.edu [128.237.27.159]) (authenticated bits=0) by redflag.CS.Princeton.EDU (8.13.8/8.13.8) with ESMTP id q4HHhowI027198 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT) for ; Thu, 17 May 2012 13:43:53 -0400 Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Apple Message framework v1278) From: Yitzhak Mandelbaum In-Reply-To: Date: Thu, 17 May 2012 13:43:53 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: References: <87d36bnafe.fsf@frosties.localnet> To: OCaml mailing list X-Mailer: Apple Mail (2.1278) Subject: Re: [Caml-list] optional functions in modules Thanks to everyone who responded. FWIW, I found the argument in favor of o= ptions 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.) >=20 > On Thu, May 10, 2012 at 2:44 PM, Goswin von Brederlow = wrote: >> Yitzhak Mandelbaum writes: >>=20 >>> Hi, >>>=20 >>> Is there any "common wisdom" regarding the inclusion of optional functi= ons in a module signature? The two most obvious approaches involve 1) a pa= ir of boolean flag and a function, where the function raises an exception i= f unimplemented OR 2) using the option type. I see pros/cons to each approa= ch, but am curious if there's any (unofficial) standard approach. >>>=20 >>> Yitzhak >>> ----------------------------- >>> Yitzhak Mandelbaum >>=20 >> The extunix module has a trifold solution for this: >>=20 >> * 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. >>=20 >> * Second there is ExtUnix.All.have : string -> bool option >>=20 >> (** [have name] >> @return indication whether function [name] is available >> - [Some true] if available >> - [Some false] if not available >> - [None] if not known >>=20 >> e.g. [have "eventfd"] >> *) >>=20 >> * Third there is ExtUnix.Specific containing only functions available on >> this platform. >>=20 >> MfG >> Goswin >>=20 >> -- >> 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 >>=20 >=20 >=20 > --=20 > 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 >=20 ----------------------------- Yitzhak Mandelbaum