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
format polymorphism
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-08-06 (23:47)
From: Christophe TROESTLER <Christophe.Troestler@u...>
Subject: format polymorphism

Could someone tell me why, say "%s", is of type

  'a. (string -> 'b, 'a, 'b) format

instead of

  'a 'b. (string -> 'b, 'a, 'b) format

I am asking this because if one wants to use the same format string
both for reading and printing in a given function, one needs the
latter type:

  type 'a fmt = { fmt: 'b 'c. ('a,'b,'c) format }
  fun  (s: _ fmt) -> Printf.printf s.fmt, Scanf.sscanf "string" s.fm

However, I cannot instantiate the type [_ fmt].  This is in contrast

  let s = ("%s": (_,_,_) format) in
  Printf.printf s, Scanf.sscanf "string" s

which works as intended.  I think this may have been discussed before;
I just can't remember the reason.  Also, is there a safe way of using
Obj.magic to make it work ?