caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Reference to polymorphic function ?
@ 2005-09-13 12:38 Ingo Bormuth
  2005-09-14 21:08 ` [Caml-list] " Stéphane Glondu
  2005-09-14 23:48 ` Jacques Garrigue
  0 siblings, 2 replies; 6+ messages in thread
From: Ingo Bormuth @ 2005-09-13 12:38 UTC (permalink / raw)
  To: caml-list; +Cc: ingo


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  |
   +--------------------------------------------------------+


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-09-15 10:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-13 12:38 Reference to polymorphic function ? Ingo Bormuth
2005-09-14 21:08 ` [Caml-list] " Stéphane Glondu
2005-09-14 23:48 ` Jacques Garrigue
2005-09-15  6:31   ` Olivier Andrieu
2005-09-15  7:00     ` Jacques Garrigue
2005-09-15 10:31   ` [SOLVED] " Ingo Bormuth

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).