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 8E0537F2E5 for ; Wed, 9 Jan 2013 11:06:13 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of mmatalka@gmail.com) identity=pra; client-ip=209.85.215.176; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="mmatalka@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of mmatalka@gmail.com designates 209.85.215.176 as permitted sender) identity=mailfrom; client-ip=209.85.215.176; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="mmatalka@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ea0-f176.google.com) identity=helo; client-ip=209.85.215.176; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="postmaster@mail-ea0-f176.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnEBADRA7VDRVdewkGdsb2JhbABEgmu6ZxYOAQEBAQkJDQcUBCOCHgEBBAEnGQEbDw4BAwELBgUhJQ8BBA8RAQUBIhMbh2kBAwkGAQubA4wzgnuEeAoZJw1ZhWABBQyRBAOIYY5HjUw/hDQ X-IronPort-AV: E=Sophos;i="4.84,436,1355094000"; d="scan'208";a="189059384" Received: from mail-ea0-f176.google.com ([209.85.215.176]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 09 Jan 2013 11:06:13 +0100 Received: by mail-ea0-f176.google.com with SMTP id d13so568455eaa.7 for ; Wed, 09 Jan 2013 02:06:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=0HH1RNyRbPCSqKOq06SJM9X5l+H0+F1JM7sFpcSDDJA=; b=kaZYqCZB9OXtNgk10qmmy9HLbRDOOSYVDLVOr2Px1iLP71qG//Fq5RgR8M8i3OtRW0 TTQ3NSbDCgxQLmKs9AMWLbPTMDl17c2aBMhl/vSDskx4bWEdI303emGgUCVAJRuupXot j/rmBLazmHXy68WKR1HyvZwGkmML1kx+AYbY+ISmgaVKBd0hXnk5v3fs7MDhypNdvAm1 11qApmqkVcT0yXfwa1Xay1a0pLv1NlcIRn+nmnLKPcAOqzyZt9XG6K5e6NJW1u+TQsZQ pLcRypHqa4oFi/V0u/4lau79FF+47tCiAeXqNxOV5tE7WbR8L6k+wznQg1YlYFOkdUDb lryA== X-Received: by 10.14.215.197 with SMTP id e45mr182055322eep.0.1357725972067; Wed, 09 Jan 2013 02:06:12 -0800 (PST) Received: from localhost ([2a01:7e00::f03c:91ff:fedf:4d21]) by mx.google.com with ESMTPS id r1sm140538594eeo.2.2013.01.09.02.06.10 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 Jan 2013 02:06:10 -0800 (PST) From: Malcolm Matalka To: David MENTRE Cc: Francois Berenger , caml-list References: <50ECE88D.9000905@riken.jp> Date: Wed, 09 Jan 2013 05:06:10 -0500 In-Reply-To: (David MENTRE's message of "Wed, 9 Jan 2013 09:38:51 +0100") Message-ID: <878v82r7ql.fsf@li195-236.members.linode.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Caml-list] some beautiful OCaml code Hey, author here, The problem polymorphic variants are solving here is that if you want to sequence unrelated functions but return their errors, you have to join their return types with the return types of the function that is calling them. Polymorphic variants basically do this for you without every function defining its own error return variant. This, so far, is the only time I have found polymorphic variants the best solution for a problem in Ocaml. /Malcolm David MENTRE writes: > Hello OCaml experts, > > 2013/1/9 Francois Berenger : >> There is a full blog post about it there: >> >> http://functional-orbitz.blogspot.se/2013/01/introduction-to-resultt-vs-exceptions.html > > 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) > """ > > 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]. > > Are the use of polymorphic variant mandatory to write code > Return-Value-style code or can regular variants be used? > > Best regards, > david > > [1] Of course this ability is the very thing that is of interest to > people using polymorphic variants.