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 821757EE79 for ; Mon, 16 May 2016 17:57:50 +0200 (CEST) IronPort-PHdr: 9a23:phKOdRH5GCWuSXZTc7qRg51GYnF86YWxBRYc798ds5kLTJ74psmwAkXT6L1XgUPTWs2DsrQf27uQ6f6rCDBIyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYsExnyfTB4Ov7yUtaLyZ/nhqbopdaCP01hv3mUX/BbFF2OtwLft80b08NJC50a7V/3mEZOYPlc3mhyJFiezF7W78a0+4N/oWwL46pyv+YJa6jxfrw5QLpEF3xmdjltvIy4gyLeVhOC7WcwVWAfkxwAQ1SUrUKyYpCknTb7su50xSyXde37S7Y5QCmj6e8/R1nohSEBOick8Wf/h8p/yqlSpVSorFpiwNiHTpuSMa9Rd6nHfN4eDVFKXstLWjYJVoy1ZZEOAu5HJu1YopPwvXMBqBK/AU+nA+a5mWwAvWP/waBvi7dpKgrBxgF1Wo9XvQ== Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-io0-f178.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.223.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.223.178 as permitted sender) identity=mailfrom; client-ip=209.85.223.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.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@mail-io0-f178.google.com) identity=helo; client-ip=209.85.223.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-io0-f178.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CyAADz7DlXj7LfVdFdDoNHN34GpyaBU4VjiwsBDYF2JIVtAoEfBzgUAQEBAQEBAQERAQEBAQcLCwkhL4ItghYBAQQSEQQZARsSCwEDDAYFCwMKAgIJHQICIgERAQUBChIGEwgKEIdyAQMXDqE3gTE+MYs7gWqCWAWHOwoZJwMKUoNVAQEBAQEFAQEBAQEaAgYQcYUkhE2HP4JZAQSGOwyRYIFWhCiIIII3jGKOAxIegQ4eAQGCOx6BGlcgMgGIBQEBAQ X-IPAS-Result: A0CyAADz7DlXj7LfVdFdDoNHN34GpyaBU4VjiwsBDYF2JIVtAoEfBzgUAQEBAQEBAQERAQEBAQcLCwkhL4ItghYBAQQSEQQZARsSCwEDDAYFCwMKAgIJHQICIgERAQUBChIGEwgKEIdyAQMXDqE3gTE+MYs7gWqCWAWHOwoZJwMKUoNVAQEBAQEFAQEBAQEaAgYQcYUkhE2HP4JZAQSGOwyRYIFWhCiIIII3jGKOAxIegQ4eAQGCOx6BGlcgMgGIBQEBAQ X-IronPort-AV: E=Sophos;i="5.24,627,1454972400"; d="scan'208";a="218432215" Received: from mail-io0-f178.google.com ([209.85.223.178]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 16 May 2016 17:57:49 +0200 Received: by mail-io0-f178.google.com with SMTP id i75so209732706ioa.3 for ; Mon, 16 May 2016 08:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=04ecwsTCzQsR7vHh86kYXTLFx0KR5QQN3hC+Tp3SSx8=; b=1AtK8X49zRSU8LV9lq0xJzayrMtvE8NbWTjiTJN4LCazwFyv/nchPvks+kkKB9vYqY XeoQsrCO/csSrgoVhtsUg9T9KiTDth1ZuMhwuVCvBuq+Tdd4s9uoapwfxriMG0ewzNhC H6W4Pz3k2uLYY2qqNJ/hDDMdU74vGuNklllFLRG0zwcWqT4alcdXr/nMmE/J5XcbUSia V1gNQ3jBcKfdujnPw9eouOnV6jUKRaKCjWYi7STF6VD0uwVrEP0wn3TsEXUWqfHZzA3V mUbQbBdPtrrSle+BFK1/+FbZxfM8VbVXKvNbHuWFvD6WFz1EJNmyMWRdFRzSmI/pI/JJ /nmw== 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:from:date :message-id:subject:to:cc; bh=04ecwsTCzQsR7vHh86kYXTLFx0KR5QQN3hC+Tp3SSx8=; b=UyyeGN+EQwEZrTKxG3m60QWgOs3V5n6a9pO9EA+KtP+8cpMPTuPFLkMJSDaRmXC3kn 0wBCAPLEPAr9dZR7ONFtngZbXK+WRFIk1YNgd+c4qHm03wp6LNbS9peXAaIkk/OxMM2H rZzfn25GajPbdIDzGoZKmzDafBicw1wakLZgZ+LUAqKoYE/qd4785pDP2Svn2nn+8fzJ cFXKIS6Pf99aVxIzZziVE80w7beLP3ZNVUZfZKCxQoAYQ7eixYoWl6rMPe+2WP15MqBJ CHsPxG2NP+PJu6BH/iPx7aSfRDiKfx/UPJN7LG3WmrQPriHWRz9fDLx4q2+zlQoS55Ri lUhA== X-Gm-Message-State: AOPr4FWkUae+hahiE8fXo811x6YrHMr7FmV3v3bojqzm2VgTXABnlP5Qq1+Dk95Or4KASIBMU9IHDSOo9S5ryA== X-Received: by 10.107.169.13 with SMTP id s13mr19118353ioe.19.1463414268367; Mon, 16 May 2016 08:57:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.89.195 with HTTP; Mon, 16 May 2016 08:57:09 -0700 (PDT) In-Reply-To: <1463412482-sup-8520@hennequin-xps> References: <1463412482-sup-8520@hennequin-xps> From: Gabriel Scherer Date: Mon, 16 May 2016 11:57:09 -0400 Message-ID: To: Guillaume Hennequin Cc: caml users Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] issue with polymorphism This is possibly, but you have to write it a bit differently. See the FAQ entry, "How to write a function with polymorphic arguments?" https://ocaml.org/learn/faq.html#Howtowriteafunctionwithpolymorphicarguments On Mon, May 16, 2016 at 11:45 AM, Guillaume Hennequin wrote: > Dear caml-list, > > let id x = x > > is polymorphic, and indeed I can apply it to various types: > > let _ = print_float (id 1.) > let _ = print_int (id 1) > > Now, say you want to write a function that takes a function of the same > ['a->'a] type as [id] above, and applies it to two different types: > > let print_both f = > print_int (f 1); > print_float (f 1.0) > > That in fact won't compile: > > Error: This expression (1.0) has type float but an expression was expected > of int > > Naively trying to enforce polymorphism doesn't work either: > > let print_both: 'a. ('a -> 'a) -> unit = fun f -> > print_int (f 1); > print_float (f 1.0) > > As a matter of fact, neither will this: > > let print1: 'a. ('a -> 'a) -> unit = fun f -> print_int (f 1) > > Error: This definition has type (int -> int) -> unit > which is less general than 'a. ('a -> 'a) -> unit > > What am I missing? How would you go about writing such a function? > > Many thanks, > Guillaume > > -- > 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