From: Ruslan Ledesma Garza <ruslanledesmagarza@gmail.com>
To: OCaml List <caml-list@inria.fr>
Subject: [Caml-list] Type generalization problem
Date: Sun, 14 Aug 2011 15:46:23 +0200 [thread overview]
Message-ID: <1F991690-DC08-4BF6-BB41-6B9402C043FC@gmail.com> (raw)
Dear list,
Consider the following OCaml session.
Objective Caml version 3.12.0
# let f : 'v . 'v -> 'v = fun x -> x;;
val f : 'a -> 'a = <fun>
# let g : 'v . 'v -> 'v = (fun x -> x) (fun x -> x);;
Error: This definition has type 'a -> 'a which is less general than
'b. 'b -> 'b
#
Why doesn't OCaml generalize the type 'a -> 'a? According to the typing rules in "Principal type-schemes for functional programs" ( http://portal.acm.org/citation.cfm?id=582176 ), the type 'a -> 'a can be generalized.
Something similar happens in the following OCaml session.
Objective Caml version 3.12.0
# let f : 'v . 'v -> 'v = fun x -> x;;
val f : 'a -> 'a = <fun>
# let h = f f;;
val h : '_a -> '_a = <fun>
# h 1;;
- : int = 1
# h h;;
Error: This expression has type int -> int
but an expression was expected of type int
#
I want the type of h to be \forall 'a . 'a -> 'a. :'(
Best regards,
Ruslán.
next reply other threads:[~2011-08-14 13:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-14 13:46 Ruslan Ledesma Garza [this message]
2011-08-14 13:55 ` Gabriel Scherer
2011-08-14 14:03 ` Ruslan Ledesma Garza
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=1F991690-DC08-4BF6-BB41-6B9402C043FC@gmail.com \
--to=ruslanledesmagarza@gmail.com \
--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