Version française
Home     About     Download     Resources     Contact us    
Browse thread
Reference to polymorphic function ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Olivier Andrieu <andrieu@i...>
Subject: Re: [Caml-list] Reference to polymorphic function ?
 Jacques Garrigue [Thursday 15 September 2005] :
 >
 > 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;;

did you mean :

 type put = {put: 'a. 'a -> unit} ;;

or is the explicit polymorphic parameter not required anymore (like
polymorphic methods in class types) ?

-- 
   Olivier