Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: -- (:)
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"

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 ?