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 B6B5B7EE36 for ; Thu, 31 Mar 2016 14:26:41 +0200 (CEST) IronPort-PHdr: 9a23:CGQlqxFLlt6g1HCn65TmlZ1GYnF86YWxBRYc798ds5kLTJ75pM6wAkXT6L1XgUPTWs2DsrQf27qQ6PirAjVIyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYsExnyfTB4Ov7yUtaLyZ/nh6bpo9aIOk1hv3mUX/BbFF2OtwLft80b08NJC50a7V/3mEZOYPlc3mhyJFiezF7W78a0+4N/oWwL46pyv50IbaKvdK09SflcDS86G2Ez/szi8xfZHiWV4X5JVW4KmxFIGQ/DpEX9VYv4mjP9svt22C6AOsuwQ6piCmfq1LtiVBK90HRPDDU+6myC0sE= Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=octa@polychoron.fr; spf=None smtp.mailfrom=octa@polychoron.fr; spf=None smtp.helo=postmaster@relay6-d.mail.gandi.net Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of octa@polychoron.fr) identity=pra; client-ip=217.70.183.198; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="octa@polychoron.fr"; x-sender="octa@polychoron.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of octa@polychoron.fr) identity=mailfrom; client-ip=217.70.183.198; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="octa@polychoron.fr"; x-sender="octa@polychoron.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@relay6-d.mail.gandi.net) identity=helo; client-ip=217.70.183.198; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="octa@polychoron.fr"; x-sender="postmaster@relay6-d.mail.gandi.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0ARAQBAFv1Wksa3RtldhAd9BrsdgXAhhWwCgT05EwEBAQEBAQEBEQEBAQEHCwsJIS+CLYIVAQEEIwQLAQVAEQsaAgUWCwICCQMCAQIBRRMIAQGIJwqwZpFKfIUhhEeEPE6CNIJWBZdyghSDX4Jyh1eHBIVVjxMCIgOCQREIgUxqAYduAX0BAQE X-IPAS-Result: A0ARAQBAFv1Wksa3RtldhAd9BrsdgXAhhWwCgT05EwEBAQEBAQEBEQEBAQEHCwsJIS+CLYIVAQEEIwQLAQVAEQsaAgUWCwICCQMCAQIBRRMIAQGIJwqwZpFKfIUhhEeEPE6CNIJWBZdyghSDX4Jyh1eHBIVVjxMCIgOCQREIgUxqAYduAX0BAQE X-IronPort-AV: E=Sophos;i="5.24,422,1454972400"; d="scan'208";a="211375062" Received: from relay6-d.mail.gandi.net ([217.70.183.198]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-GCM-SHA384; 31 Mar 2016 14:26:41 +0200 Received: from mfilter19-d.gandi.net (mfilter19-d.gandi.net [217.70.178.147]) by relay6-d.mail.gandi.net (Postfix) with ESMTP id 0F53FFB8D6 for ; Thu, 31 Mar 2016 14:26:41 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter19-d.gandi.net Received: from relay6-d.mail.gandi.net ([IPv6:::ffff:217.70.183.198]) by mfilter19-d.gandi.net (mfilter19-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id BDag2veYsI0F for ; Thu, 31 Mar 2016 14:26:38 +0200 (CEST) X-Originating-IP: 194.57.247.3 Received: from [172.22.8.126] (fw.enpc.fr [194.57.247.3]) (Authenticated sender: octa@polychoron.fr) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 5787BFB8BF for ; Thu, 31 Mar 2016 14:26:38 +0200 (CEST) To: caml-list@inria.fr References: <56FD12CC.20509@libertysurf.fr> From: octachron Message-ID: <56FD177D.2020300@polychoron.fr> Date: Thu, 31 Mar 2016 14:26:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <56FD12CC.20509@libertysurf.fr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] explicit polymorphic type annotation Hi, In order to pass a polymorphic function to your rank-2 function f, you need to encapsulate it eitheir in a record: type poly = { f: 'a. 'a -> 'a } let func = {f = (fun x -> x) } let f func = func.f 1, func.f 2. or in an object let func = object method f:'a.'a->'a = fun x -> x end let f (func: 'a>) = func#f 1, func#f 2.;; There is a section on polymorphic method in the manual here: http://caml.inria.fr/pub/docs/manual-ocaml/objectexamples.html#sec34 and explicit polymorphic type for record field are briefly mentioned at the end of http://caml.inria.fr/pub/docs/manual-ocaml/coreexamples.html#sec12. Regards, octachron Le 03/31/16 14:06, William a écrit : > Hi, > > I don't know how to handle this, and can not find how to do it in the > manual. I would like "func" to be polymorphic : > > let f func = > Printf.printf "%i\n%!" (func (1,2)); > Printf.printf "%f\n%!" (func (1.,2.));; > f fst;; > f snd;; > > => > Characters 85-87: > Printf.printf "%f\n%!" (func (1.,2.));; > ^^ > Error: This expression has type float but an expression was expected > of type int > > > let f (func:('a. 'a * 'a -> 'a)) = > Printf.printf "%i\n%!" (func (1,2)); > Printf.printf "%f\n%!" (func (1.,2.));; > f fst;; > f snd;; > > => > Characters 15-16: > let f (func:('a. 'a * 'a -> 'a)) = > ^ > Error: Syntax error: type expected. > > > > Could someone show me how to handle this ? > > Also, I did not find any relevant chapter in ocaml.org or ocaml > reference manual to explain how to do. Any pointers ? > > Best regards >