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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 93A8F7F30A for ; Wed, 9 Jan 2013 14:15:40 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=pra; client-ip=212.227.126.187; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=mailfrom; client-ip=212.227.126.187; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of postmaster@moutng.kundenserver.de designates 212.227.126.187 as permitted sender) identity=helo; client-ip=212.227.126.187; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="postmaster@moutng.kundenserver.de"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhgBAFVs7VDU4367k2dsb2JhbABEqn2SVBYOAQEBAQkJCwkUAySCHgEBBAEnEzEDEB4dXQkSBhMJCYdzAwkKCJdGl1kDhkkUkHwDjWaJQpIi X-IronPort-AV: E=Sophos;i="4.84,436,1355094000"; d="scan'208";a="167869058" Received: from moutng.kundenserver.de ([212.227.126.187]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 09 Jan 2013 14:15:39 +0100 Received: from office1.lan.sumadev.de (dslb-094-219-213-010.pools.arcor-ip.net [94.219.213.10]) by mrelayeu.kundenserver.de (node=mrbap4) with ESMTP (Nemesis) id 0LtnQD-1Srz701egX-011FE2; Wed, 09 Jan 2013 14:15:39 +0100 Received: from samsung (ip-5-146-55-186.unitymediagroup.de [5.146.55.186]) by office1.lan.sumadev.de (Postfix) with ESMTPSA id E6369C00D0 for ; Wed, 9 Jan 2013 14:15:38 +0100 (CET) Date: Wed, 09 Jan 2013 14:15:38 +0100 From: Gerd Stolpmann Reply-To: Gerd Stolpmann To: caml-list In-Reply-To: X-Mailer: Balsa 2.4.11 Message-Id: <1357737338.28639.11@samsung> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; DelSp=Yes; Format=Flowed Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-Provags-ID: V02:K0:rJ9CPCyrA47kNy1P3hJYVv7Eyw02TaM5YHPEVdkiX5m apEFMF05hpPbjJh7lyWpfQCHfFWYmycTwq98nV1po67bstHmaw MSd8SS6v3pw70tDUD0W+u9GV9csM8EikiL1WY22x+HK9QishTE FNHkiRTxtLVLogLp+8y68JvVKxte8T6UemzF1MSQeE8I1lh37+ ZLWkomzsUX+2rDOkMk74ujti30aJgTPY0R2/osIKshG6iwi779 0qgJ9oI/HZRDCvss0JsM/Da77ifcVQq0Ft2e3VlTPvR8KHCfsx btoJw2ra8KyTnVsS0UMP/6KqOezI8p93EIQPvy+/ka/LbrVY7T oPNKgC9fCkQ01m64CUWkqwmNyqWz9rwEqKaJjURfU Subject: AW: [Caml-list] some beautiful OCaml code Am 09.01.2013 09:38:51 schrieb(en) David MENTRE: > Hello OCaml experts, >=20 > 2013/1/9 Francois Berenger : > > There is a full blog post about it there: > > > >=20=20 > http://functional-orbitz.blogspot.se/2013/01/introduction-to-resultt-vs-e= xceptions.html >=20 > Regarding this blog post, the final code is using Polymorphic Variants > (http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html#toc36). > E.g. > """ > | _ -> > Error (`Bad_line s) > """ >=20 > I never fully grasped polymorphic variants compared to regular ones > but I always had the feeling the polymorphic variants where less safe > that variants because they would allow more possibility to mix > unrelated things[1]. That's exactly the point: Polyvariants allow you to mix unrelated=20=20 things. I don't think, though, that they are unsafer, because you get=20=20 help from the compiler to keep these things nevertheless separated. You=20= =20 need to be aware what can happen, and here and there it is helpful to=20=20 add a type hint or a coercion to control typing. > Are the use of polymorphic variant mandatory to write code > Return-Value-style code or can regular variants be used? No. You can also use normal variants, but of course you need then a=20=20 declaration like type error =3D Bad_line of string | Bad_name of string | ... before using it. Also, function composition can be very painful.=20=20 Imagine you wrote two modules M1 and M2 in this style, and each module=20= =20 defines an error type. Now you want to call functions from both modules=20= =20 at one place, and run into the problem that you get [Error e1] values=20=20 with [e1:M1.error_type] and [Error e2] values with [e2:M2.error_type].=20= =20 There is no simple way to mix that. Probably you need to do type error =3D M1_error of M1.error | M2_error of M2.error which is kind of inelegant. Polyvariants, in contrast, allow you to=20=20 directly unite the error types as long as the tags are not=20=20 contradictory. This means function composition as again as easy as if=20=20 you used exceptions for error reporting. Gerd > Best regards, > david >=20 > [1] Of course this ability is the very thing that is of interest to > people using polymorphic variants. >=20 > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >=20 >=20 --=20 ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de Creator of GODI and camlcity.org. Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------=