From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 5E48ABB9C for ; Thu, 15 Sep 2005 01:48:35 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j8ENmY0G016083 for ; Thu, 15 Sep 2005 01:48:35 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA11264 for ; Thu, 15 Sep 2005 01:48:34 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j8ENmWFw016078 for ; Thu, 15 Sep 2005 01:48:33 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id j8ENmQJT009873; Thu, 15 Sep 2005 08:48:26 +0900 (JST) Date: Thu, 15 Sep 2005 08:48:14 +0900 (JST) Message-Id: <20050915.084814.127622622.garrigue@math.nagoya-u.ac.jp> To: ibormuth@efil.de Cc: caml-list@inria.fr Subject: Re: [Caml-list] Reference to polymorphic function ? From: Jacques Garrigue In-Reply-To: <20050913123843.GA9640@kruemel> References: <20050913123843.GA9640@kruemel> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4328B6D2.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4328B6D0.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 val:01 resolving:01 ingo:98 efil:98 polymorphic:01 polymorphic:01 expression:01 define:01 explicitly:01 int:01 jacques:01 jacques:01 href:98 closure:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 From: Ingo Bormuth > Nevertheless, if I store the polymorphic function in a reference to > create a closure for all kinds of output methodeis, any attemps to use > that function are thwarted by the type interferer. > > # let put = ref put_to_screen ;; > val put : ('_a -> unit) ref = {contents = } > > # !put "test" ;; > %%%%%%test- : unit = () > > # !put 5 ;; > This expression has type int but is here used with type string > > How can I keep the interferer from explicitly resolving the type of v ? You cannot: this would be unsound. Actually, this is the opposite: you want to tell in advance the inferer that put is polymorphic, and that only polymorphic values should be accepeted. The simplest way to do this is to define a new type: type put = {put: 'a -> unit} ;; let put = {put = put_to_screen} ;; put.put "test";; put.put 5;; --------------------------------------------------------------------------- Jacques Garrigue Nagoya University garrigue at math.nagoya-u.ac.jp JG