caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: William <r.3@libertysurf.fr>
To: caml-list@inria.fr
Subject: [Caml-list] explicit polymorphic type annotation
Date: Thu, 31 Mar 2016 14:06:36 +0200	[thread overview]
Message-ID: <56FD12CC.20509@libertysurf.fr> (raw)

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

             reply	other threads:[~2016-03-31 12:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-31 12:06 William [this message]
2016-03-31 12:26 ` octachron
2016-04-02 11:40   ` Goswin von Brederlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56FD12CC.20509@libertysurf.fr \
    --to=r.3@libertysurf.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).