English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Printing of polymorphic values in #trace
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-05-02 (17:48)
From: Harrison, John R <johnh@i...>
Subject: Printing of polymorphic values in #trace
I wanted to suggest a little change to tracing. I can imagine that this
might be hard, depending on what type information is available at
certain times. But if it's moderately easy I think it would be worth the

When displaying the input and output values for a function, OCaml seems
to use the most general types, and therefore polymorphic functions often
fail to print anything useful. For example:

  $ ocaml
        Objective Caml version 3.08.2

  # let identity x = x;;
  val identity : 'a -> 'a = <fun>
  # #trace identity;;
  identity is now traced.
  # identity 1;;
  identity <-- <poly>
  identity --> <poly>
  - : int = 1

If on the other hand I explicitly constrain the type of "identity", I
get the effect I want:

  # let identity (x:int) = x;;
  val identity : int -> int = <fun>
  # #trace identity;;
  identity is now traced.
  # identity 1;;
  identity <-- 1
  identity --> 1
  - : int = 1

It would be nice if OCaml did this automatically, since the type
of the instance actually used is the same in each case.