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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id A2FB17F30A for ; Wed, 13 Mar 2013 03:01:58 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=pra; client-ip=133.6.130.5; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=mailfrom; client-ip=133.6.130.5; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mailhost.math.nagoya-u.ac.jp) identity=helo; client-ip=133.6.130.5; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="postmaster@mailhost.math.nagoya-u.ac.jp"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap8EALDdP1GFBoIF/2dsb2JhbABDxHKBYnSCKQEBBAEnEwkBNQIDCwsOOCE2BhOIAgMJBa5RhEEChH4NTIkIB4xFghUzB4JfYYh0jAWBYIEfij6FGYMZLQ X-IPAS-Result: Ap8EALDdP1GFBoIF/2dsb2JhbABDxHKBYnSCKQEBBAEnEwkBNQIDCwsOOCE2BhOIAgMJBa5RhEEChH4NTIkIB4xFghUzB4JfYYh0jAWBYIEfij6FGYMZLQ X-IronPort-AV: E=Sophos;i="4.84,833,1355094000"; d="scan'208";a="5879758" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail3-smtp-sop.national.inria.fr with ESMTP; 13 Mar 2013 03:01:42 +0100 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 766A36345; Wed, 13 Mar 2013 11:01:39 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 4CAB53960; Wed, 13 Mar 2013 11:01:39 +0900 (JST) DomainKey-Signature: h=Received:Subject:Mime-Version:Content-Type:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=; c=nofws; d=math.nagoya-u.ac.jp; q=; s=alpha Received: from garrigue-mini.math.nagoya-u.ac.jp (garrigue-mini.math.nagoya-u.ac.jp [172.16.30.37]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 439F9252E; Wed, 13 Mar 2013 11:01:39 +0900 (JST) Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Content-Type: text/plain; charset=us-ascii From: Jacques Garrigue In-Reply-To: <87ip4wffhd.fsf@li195-236.members.linode.com> Date: Wed, 13 Mar 2013 11:06:54 +0900 Cc: caml-list@inria.fr Content-Transfer-Encoding: quoted-printable Message-Id: References: <87ip4wffhd.fsf@li195-236.members.linode.com> To: Malcolm Matalka X-Mailer: Apple Mail (2.1499) Subject: Re: [Caml-list] Type variables and polymorphic variants On 2013/03/13, at 6:57, Malcolm Matalka wrote: > Hello! I use polymorphic variants extensively in my code for getting > the compiler to make sure I handle errors. However, I'm trying to write > the following function which is proving hard, the errors are below. >=20 > I have come across similar issues before and it is related to the type > variable. I believe the problem is the [> in error because it can't know > if I return a polymorphic variant in this function if that is the error > or not. >=20 > What is the cleanest way to write this function? >=20 > val with_conn : > host:string -> > port:int -> > (unit -> ('a, [> error ]) Deferred.Result.t) -> > ('a, [> error ]) Deferred.Result.t >=20 >=20 > Error: The implementation conn.ml does not match the interface conn.cmi: > Values do not match: > val with_conn : > host:string -> > port:int -> > (unit -> > ('a, [> `Bad_conn ] as 'b) Core.Std._result > Async_core.Deferred.t) -> > ('a, 'b) Core.Std._result Async_core.Deferred.t > is not included in > val with_conn : > host:string -> > port:int -> > (unit -> ('a, [> error ]) Async.Std.Deferred.Result.t) -> > ('a, [> error ]) Async.Std.Deferred.Result.t >=20 The hint is in the error message: > (unit -> ('a, [> `Bad_conn ] as 'b) Core.Std._result Async_cor= e.Deferred.t) -> > ('a, 'b) Core.Std._result Async_core.Deferred.t You must use an "as" to connect the types: val with_conn : host:string -> port:int -> (unit -> ('a, [> error ] as 'e) Deferred.Result.t) -> ('a, 'e) Deferred.Result.t Jacques Garrigue=