caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: ibormuth@efil.de
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Reference to polymorphic function ?
Date: Thu, 15 Sep 2005 08:48:14 +0900 (JST)	[thread overview]
Message-ID: <20050915.084814.127622622.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20050913123843.GA9640@kruemel>

From: Ingo Bormuth <ibormuth@efil.de>

> 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 = <fun>}
> 
>     # !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
		   <A HREF=http://www.math.nagoya-u.ac.jp/~garrigue/>JG</A>


  parent reply	other threads:[~2005-09-14 23:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-13 12:38 Ingo Bormuth
2005-09-14 21:08 ` [Caml-list] " Stéphane Glondu
2005-09-14 23:48 ` Jacques Garrigue [this message]
2005-09-15  6:31   ` Olivier Andrieu
2005-09-15  7:00     ` Jacques Garrigue
2005-09-15 10:31   ` [SOLVED] " Ingo Bormuth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050915.084814.127622622.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=ibormuth@efil.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).