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 0E9E17FBBC for ; Thu, 8 Jan 2015 10:45:51 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of bmillwood@janestreet.com) identity=pra; client-ip=38.105.200.112; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="bmillwood@janestreet.com"; x-sender="bmillwood@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of bmillwood@janestreet.com designates 38.105.200.112 as permitted sender) identity=mailfrom; client-ip=38.105.200.112; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="bmillwood@janestreet.com"; x-sender="bmillwood@janestreet.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mxout1.mail.janestreet.com) identity=helo; client-ip=38.105.200.112; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="bmillwood@janestreet.com"; x-sender="postmaster@mxout1.mail.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al0AAAJRrlQmachwnGdsb2JhbABcg1hYBIMBszeNXYFfAQmFcwKBCQdDAQEBAQERAQEBAQEGFglChAwBAQEDARIRBBkBASwLAQQLCwQHDQ0dAgIhARIBBQEKEgYTEhCHdgMJCAMKpX0+MYo+cIRiAQWLLgMKFYMyAQEBAQEBAQMBAQEBAQEBAQEBAREGCo1FgiYEB4ItOxGBMIQ8Bo05hACBRIEOMIpTgiSBbxIjgRWEEG+CQwEBAQ X-IPAS-Result: Al0AAAJRrlQmachwnGdsb2JhbABcg1hYBIMBszeNXYFfAQmFcwKBCQdDAQEBAQERAQEBAQEGFglChAwBAQEDARIRBBkBASwLAQQLCwQHDQ0dAgIhARIBBQEKEgYTEhCHdgMJCAMKpX0+MYo+cIRiAQWLLgMKFYMyAQEBAQEBAQMBAQEBAQEBAQEBAREGCo1FgiYEB4ItOxGBMIQ8Bo05hACBRIEOMIpTgiSBbxIjgRWEEG+CQwEBAQ X-IronPort-AV: E=Sophos;i="5.07,721,1413237600"; d="scan'208";a="95714340" Received: from mxout1.mail.janestreet.com ([38.105.200.112]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 08 Jan 2015 10:45:49 +0100 Received: from tot-qpr-mailcore1.delacy.com ([172.27.56.68] helo=tot-qpr-mailcore1) by mxout1.mail.janestreet.com with smtp (Exim 4.82) (envelope-from ) id 1Y99f2-0000s5-6J for caml-list@inria.fr; Thu, 08 Jan 2015 04:45:48 -0500 X-JS-Flow: external Received: by tot-qpr-mailcore1 with JS-mailcore (0.1) (envelope-from ) id BUrlHM-AAACfG-Fj; 2015-01-08 04:45:48.178659-05:00 Received: from mail-qc0-f171.google.com ([209.85.216.171]) by mxgoog1.mail.janestreet.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.72) (envelope-from ) id 1Y99f2-0007BY-1S for caml-list@inria.fr; Thu, 08 Jan 2015 04:45:48 -0500 Received: by mail-qc0-f171.google.com with SMTP id r5so1079631qcx.2 for ; Thu, 08 Jan 2015 01:45:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=3w6gHCZO6Eci0BahSy5OtL/liNyKnLkgnExBrEIxOss=; b=CoDYJwuMbqSNhLV6bhdRn1tQZxyCjxIm9IGhAiGlqdjemjM/aK3lHFtMYY1Z3avogA 0GnYUG+MyHHYnxs4zwqPRSSH8F/rLWJqTHILNTay4yv8yt7yLbR4Y5H8WaSmngwmYlrQ wl805nnOmyQ0XgUwqyHtmwlH72Fl/P+yhqEfI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=3w6gHCZO6Eci0BahSy5OtL/liNyKnLkgnExBrEIxOss=; b=jQo9aop4KHYyWzqFizyNxjF9hMc3nI+sqglthqfFWbQ3czzp32lKtf0bww3pu0dW96 4ZWeCWJtounrhPgqA68KWuUx+xWfNs6ZYSvRI0n6oeppvWYkNk5Wwcl0qXXKlOhiMttO JAGa78h7UDySZrzJeV001Y4dPr7M5UGEE1nHCN2uP6vaazTNFbMKB7DhUSdTuIzlVLXs 69e3TAokQIFa9WPkKbLiLg9Du2wep1rmYmFJ4ssKsPMcWN7srhTPX6aCaMDVQnu3Sacc a7iJe+swX94yEOLfyOK15FITnsPQgKNWcDkaXiP+CK+Qh5gk3iRdtAK8t0i1WCWSXrMd ulpA== X-Gm-Message-State: ALoCoQkCouABjUMlVFwDlFvabnz8ZjdDOw8mOsRizmo3vKOM8FGYAubNrjO2IDk5ZdXHKrpdm1XR14JaxIEN8R9xFNiGpQV1Y1c42vnntAaeT//0pEZQEO/3dHo/DpMb8w9FsHrj4fnW X-Received: by 10.229.61.5 with SMTP id r5mr13684114qch.28.1420710347809; Thu, 08 Jan 2015 01:45:47 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.229.61.5 with SMTP id r5mr13684096qch.28.1420710347663; Thu, 08 Jan 2015 01:45:47 -0800 (PST) Received: by 10.140.19.209 with HTTP; Thu, 8 Jan 2015 01:45:47 -0800 (PST) In-Reply-To: References: <20150107135012.GA17784@frosties> Date: Thu, 8 Jan 2015 09:45:47 +0000 Message-ID: From:Ben Millwood To:Jeremy Yallop Cc:Goswin von Brederlow , caml users Content-Type: multipart/alternative; boundary=001a1132e4b49a13b5050c20e718 X-JS-Processed-by: mailcore Subject: Re: [Caml-list] Problem with universal functions in a module --001a1132e4b49a13b5050c20e718 Content-Type: text/plain; charset=UTF-8 Parametric polymorphic values in OCaml's type system can be thought of as "choose an assignment of the variables in this type, and you can use this value with that monomorphic type". But there's no monomorphic type that lets 'helper' do the right thing, so you actually need something more expressive than ordinary polymorphic types. In Haskell there's higher-rank polymorphism, which in this case would look something like 'helper :: (forall a. T a -> b) -> Helper b', so that you could only pass sufficiently-polymorphic arguments to helper. However, as Jeremy said, there's a lot of added complexity involved. On 7 January 2015 at 17:26, Jeremy Yallop wrote: > On 7 January 2015 at 13:50, Goswin von Brederlow > wrote: > > Why are function arguments less general than their original function? > > Polymorphic arguments complicate type checking and make type inference > impossible, so OCaml doesn't allow them. > > > B) is there some way around this I'm not seeing? > > I don't think that there's any way of passing polymorphic arguments > that works out simpler than using a record. > > Of course, in your simple example code it's possible to eliminate the > GADT altogether, which would also eliminate the need for polymorphic > arguments. Perhaps GADTs play a more essential role in your real > code, though. > > -- > 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 > --001a1132e4b49a13b5050c20e718 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Parametric polymorphic values in OCaml's type sys= tem can be thought of as "choose an assignment of the variables in thi= s type, and you can use this value with that monomorphic type". But th= ere's no monomorphic type that lets 'helper' do the right thing= , so you actually need something more expressive than ordinary polymorphic = types.

In Haskell there's higher-rank polymorphism, which = in this case would look something like 'helper :: (forall a. T a -> = b) -> Helper b', so that you could only pass sufficiently-polymorphi= c arguments to helper. However, as Jeremy said, there's a lot of added = complexity involved.

On 7 January 2015 at 17:26, Jeremy Yallop &l= t;yallop@gmail.com> wrote:
On 7= January 2015 at 13:50, Goswin von Brederlow <goswin-v-b@web.de> wrote:
> Why are function arguments less general than their original function?<= br>
Polymorphic arguments complicate type checking and make type inferen= ce
impossible, so OCaml doesn't allow them.

> B) is there some way around this I'm not seeing?

I don't think that there's any way of passing polymorphic ar= guments
that works out simpler than using a record.

Of course, in your simple example code it's possible to eliminate the GADT altogether, which would also eliminate the need for polymorphic
arguments.=C2=A0 Perhaps GADTs play a more essential role in your real
code, though.

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
ht= tps://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

--001a1132e4b49a13b5050c20e718--