[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jacques Garrigue <garrigue@m...> |
| Subject: | Re: [Caml-list] Reference to polymorphic function ? |
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>