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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 83EC97EE99 for ; Sun, 19 Jan 2014 07:19:14 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of oleg@okmij.org) identity=pra; client-ip=66.39.3.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="oleg@okmij.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of oleg@okmij.org designates 66.39.3.115 as permitted sender) identity=mailfrom; client-ip=66.39.3.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="oleg@okmij.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@www1.g3.pair.com) identity=helo; client-ip=66.39.3.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="postmaster@www1.g3.pair.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApQSANVt21JCJwNzY2dsb2JhbABZg0OIMK9eg36BHAMYBw4IPIIlAQEBAgEBJ1cWNGk0h2IIDZhVq0MXjQSCAhaEIgSYIQGBMpQTPA X-IPAS-Result: ApQSANVt21JCJwNzY2dsb2JhbABZg0OIMK9eg36BHAMYBw4IPIIlAQEBAgEBJ1cWNGk0h2IIDZhVq0MXjQSCAhaEIgSYIQGBMpQTPA X-IronPort-AV: E=Sophos;i="4.95,683,1384297200"; d="scan'208";a="53869968" Received: from www1.g3.pair.com ([66.39.3.115]) by mail2-smtp-roc.national.inria.fr with SMTP; 19 Jan 2014 07:19:13 +0100 Received: (qmail 72148 invoked by uid 9370); 19 Jan 2014 06:19:13 -0000 Date: 19 Jan 2014 06:19:13 -0000 Message-ID: <20140119061913.72147.qmail@www1.g3.pair.com> From: oleg@okmij.org To: caml-list@inria.fr In-reply-to: <02dd01cf13ed$9f391950$ddab4bf0$@ffconsultancy.com> Subject: Re: [Caml-list] How much optimized is the 'a option type ? > let rec iter_stream f s = > match (try Some (MyStream.get s) with End_of_stream -> None) with > | None -> () > | Some (x, s') -> > f x; > iter_stream f s' > > where an option is used to keep the function tail-rec (I've heard > several people tell me they often need to use this), or other cases > like optional parameters (which are not going to move to Either), > would be useful and future-proof. I concur this is a very common pattern. The immediate thought is that perhaps functions like MyStream.get should return an (('result,'error) either) value rather than throw an exception. But there is a better solution, described in Exceptional Syntax Nick Benton and Andrew Kennedy. In Journal of Functional Programming, 11(4): 395-410, July 2001. http://research.microsoft.com/en-us/um/people/akenn/sml/ExceptionalSyntax.pdf Incidentally, the example presented in Sec 3 of the paper is almost exactly like the example mentioned on this thread. It is a common problem, and luckily a good solution has been designed and well explained. I guess what's lacking is time to implement it.