caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] explicit polymorphic type annotation
@ 2016-03-31 12:06 William
  2016-03-31 12:26 ` octachron
  0 siblings, 1 reply; 3+ messages in thread
From: William @ 2016-03-31 12:06 UTC (permalink / raw)
  To: caml-list

Hi,

I don't know how to handle this, and can not find how to do it in the 
manual. I would like "func" to be polymorphic :

let f func =
   Printf.printf "%i\n%!" (func (1,2));
   Printf.printf "%f\n%!" (func (1.,2.));;
f fst;;
f snd;;

=>
Characters 85-87:
Printf.printf "%f\n%!" (func (1.,2.));;
                               ^^
Error: This expression has type float but an expression was expected of 
type int


let f (func:('a. 'a * 'a -> 'a)) =
   Printf.printf "%i\n%!" (func (1,2));
   Printf.printf "%f\n%!" (func (1.,2.));;
f fst;;
f snd;;

=>
Characters 15-16:
let f (func:('a. 'a * 'a -> 'a)) =
                ^
Error: Syntax error: type expected.



Could someone show me how to handle this ?

Also, I did not find any relevant chapter in ocaml.org or ocaml 
reference manual to explain how to do. Any pointers ?

Best regards

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

end of thread, other threads:[~2016-04-02 11:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-31 12:06 [Caml-list] explicit polymorphic type annotation William
2016-03-31 12:26 ` octachron
2016-04-02 11:40   ` Goswin von Brederlow

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