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 6EC5A81792 for ; Mon, 1 Jul 2013 09:38:06 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of dra-news@metastack.com) identity=pra; client-ip=81.103.221.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="dra-news@metastack.com"; x-conformance=sidf_compatible Received-SPF: Neutral (mail2-smtp-roc.national.inria.fr: domain of dra-news@metastack.com does not assert whether or not 81.103.221.52 is permitted sender) identity=mailfrom; client-ip=81.103.221.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="dra-news@metastack.com"; 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@mtaout04-winn.ispmail.ntl.com) identity=helo; client-ip=81.103.221.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="postmaster@mtaout04-winn.ispmail.ntl.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnABALov0VFRZ900nGdsb2JhbABaxBoWDgEBAQEBBg0JCRQogioIAh0BEkwFFlIjHAEEHgWIA5tVn1WTTAOOdZ0q X-IPAS-Result: AnABALov0VFRZ900nGdsb2JhbABaxBoWDgEBAQEBBg0JCRQogioIAh0BEkwFFlIjHAEEHgWIA5tVn1WTTAOOdZ0q X-IronPort-AV: E=Sophos;i="4.87,972,1363129200"; d="scan'208";a="24038468" Received: from mtaout04-winn.ispmail.ntl.com ([81.103.221.52]) by mail2-smtp-roc.national.inria.fr with ESMTP; 01 Jul 2013 09:38:05 +0200 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout04-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20130701073804.KONG22777.mtaout04-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com> for ; Mon, 1 Jul 2013 08:38:04 +0100 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout02-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20130701073804.GGSL6472.aamtaout02-winn.ispmail.ntl.com@romulus.metastack.com> for ; Mon, 1 Jul 2013 08:38:04 +0100 Received: from Altus ([172.16.0.18]) (authenticated bits=0) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id r617c2Io012883 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Mon, 1 Jul 2013 08:38:02 +0100 From: "David Allsopp" To: "OCaml List" Date: Mon, 1 Jul 2013 08:39:24 +0100 Organization: MetaStack Solutions Ltd. Message-ID: <001001ce762e$1bedde30$53c99a90$@metastack.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: Ac5107TD1jtSHaCJRjqtEYjvpka/1Q== Content-Language: en-gb X-Scanned-By: MIMEDefang 2.65 on 172.16.0.20 X-Cloudmark-Analysis: v=1.1 cv=GaEGOwq9FwezmTggA+b6yC6zDZF2HYaK6RN/tSqdnVA= c=1 sm=0 a=cTs9vV391PwA:10 a=RQQLJnld3ZcA:10 a=kj9zAlcOel0A:10 a=8yrj_kC9WGaGYVWdiNAA:9 a=CjuIK1q_8ugA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Subject: [Caml-list] Mixing two GADTs Suppose I have the following two GADTs: type _ foo = A : int foo | B : string foo | C : bool foo type _ bar = X : int bar | Y : float bar | Z : string bar In my actual use case, these two GADTs cannot be altered. Suppose I then define the following two functions: let g : type s . s bar -> s = function X -> 42 | Y -> 42.0 | Z -> "42" let get1 : type s . s foo -> s = function A -> int_of_string (g Z) | B -> string_of_float (g Y) | C -> (=) 1 (g X) So far, so good. Now what I'd like to try to do is alter get1 to be of the form: let get2 : type s . s foo -> s = fun attr -> let (f, retr) = match attr with A -> (int_of_string, Z) | B -> (string_of_float, Y) | C -> ((=) 1, X) in f (g retr) Obviously, I need type annotations for f and retr. I'd tried: let get2 : type s . s foo -> s = fun attr -> let x : type t . (t -> s) * t bar = match attr with A -> (int_of_string, Z) | B -> (string_of_float, Y) | C -> ((=) 1, X) in let (f, retr) = x in f (g retr) But I get an error with int_of_string being of type string -> int instead of type t -> s. (Incidentally, the notation I expected to be able to use of [(let ((f, retr) : type t . (t -> s) * t bar)] resulted in a syntax error although looking at 7.13 in the manual, I think that's probably correct?) Is there a type annotation which will allow this to work? Any help (or a statement that this happens to be impossible!) much appreciated... David