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 31EC37FA66 for ; Mon, 16 May 2016 17:46:03 +0200 (CEST) IronPort-PHdr: 9a23:PomzFBUoPC+H0tuBuHYmqdjZgInV8LGtZVwlr6E/grcLSJyIuqrYZhCOt8tkgFKBZ4jH8fUM07OQ6PCxHzZeqsfY+Fk5M7VyFDY9wf0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5K6zPF5LIiIzvjqbpq8yVOVsD1WP1SIgxBSv1hD2ZjtMRj4pmJ/R54TryiVwMRd5rw3h1L0mYhRf265T41pdi9yNNp6BprJYYAu2pN5g/GLdRCTBjN2Eu+OXqswPCRE2B/CgySGITxzVVAgzB5Qz/U9/Rvy38u/Ng2S/SacKwTb0yXzm78qZtYBLuh2EMPjt/+WqRl88m3/ETmw6ouxEqm92cW4qSLvcrJq4= Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gjeh2@cam.ac.uk; spf=None smtp.mailfrom=gjeh2@cam.ac.uk; spf=Pass smtp.helo=postmaster@ppsw-42.csi.cam.ac.uk Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gjeh2@cam.ac.uk) identity=pra; client-ip=131.111.8.142; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gjeh2@cam.ac.uk"; x-sender="gjeh2@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gjeh2@cam.ac.uk) identity=mailfrom; client-ip=131.111.8.142; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gjeh2@cam.ac.uk"; x-sender="gjeh2@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@ppsw-42.csi.cam.ac.uk designates 131.111.8.142 as permitted sender) identity=helo; client-ip=131.111.8.142; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gjeh2@cam.ac.uk"; x-sender="postmaster@ppsw-42.csi.cam.ac.uk"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CLAQCb6jlXkI4Ib4NdrC+DM5hSPBABAQEBAQEBAREBAQEBBw0JCSEvgi2CPwQLAQVSJAImAhJBiE4EnzSPYo0bhBSBAYUkiViCNIJZBZgnl12FWo9BN4FhDAGCKohzAQEB X-IPAS-Result: A0CLAQCb6jlXkI4Ib4NdrC+DM5hSPBABAQEBAQEBAREBAQEBBw0JCSEvgi2CPwQLAQVSJAImAhJBiE4EnzSPYo0bhBSBAYUkiViCNIJZBZgnl12FWo9BN4FhDAGCKohzAQEB X-IronPort-AV: E=Sophos;i="5.24,627,1454972400"; d="scan'208";a="218431329" Received: from ppsw-42.csi.cam.ac.uk ([131.111.8.142]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 May 2016 17:46:02 +0200 X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from [82.132.185.16] (port=7910 helo=hennequin-xps.local) by ppsw-42.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.158]:587) with esmtpsa (PLAIN:gjeh2) (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1b2KiY-000PVG-6l (Exim 4.86_36-e07b163) for caml-list@inria.fr (return-path ); Mon, 16 May 2016 16:46:02 +0100 Received: from hennequi by hennequin-xps.local with local (Exim 4.87) (envelope-from ) id 1b2KiP-0003q8-Pe for caml-list@inria.fr; Mon, 16 May 2016 16:45:53 +0100 Content-Type: text/plain; charset=UTF-8; format=flowed From: Guillaume Hennequin To: caml-list@inria.fr Date: Mon, 16 May 2016 16:45:53 +0100 Message-Id: <1463412482-sup-8520@hennequin-xps> User-Agent: Sup/0.22.1 Content-Transfer-Encoding: 8bit Sender: "G.J.E. Hennequin" X-Validation-by: g.hennequin@eng.cam.ac.uk Subject: [Caml-list] issue with polymorphism 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