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: Ingo Bormuth <ibormuth@e...>
Subject: Reference to polymorphic function ?

Hi list,

the following declaration of put_to_screen nicely accepts all kinds 
of values as v. This is the expected behaviour.

    # let put_to_screen v = print_string ( Marshal.to_string v [] ) ;;
    val put_to_screen : 'a -> unit = <fun>

    # put_to_screen "test" ;;
    %%%%%test- : unit = ()

    # put_to_screen 5 ;;     
    %%%%%E- : unit = ()

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 ?

    # put;;
    - : (string -> unit) ref = {contents = <fun>}


Thanks !

-- 
   +--------------------------------------------------------+
   | Ingo Bormuth,  voicebox & telefax: +49-12125-10226517  |
   | GnuPG key 86326EC9 at http://ibormuth.efil.de/contact  |
   +--------------------------------------------------------+