From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
To: Christophe Papazian <christophe.papazian@gmail.com>
Cc: Goswin von Brederlow <goswin-v-b@web.de>, caml-list@inria.fr
Subject: Re: [Caml-list] Odd failure to infer types
Date: Sat, 3 Sep 2011 13:42:14 +0200 [thread overview]
Message-ID: <20110903114214.GZ15100@localhost> (raw)
In-Reply-To: <E43428B9-330B-422E-9803-F10D53278FA0@gmail.com>
Le Saturday 03 Sep 2011 à 12:31:59 (+0200), Christophe Papazian a écrit :
> The type of [] is 'a list. This is (strong) polymorphism. Calling a
> function 'int list -> ?' on [] doesn't not
> remove the polymorphism of []. However, an '_a list array is not
> polymorphism, it's just the compiler who don't know
> yet the type inside the lists. And as you give him [], he can't
> deduce the type.
>
> As an example you can do this :
>
> let s = [] in 1::s, 'a'::s, [|s|] ;;
>
> And it still doesn't know...
Ah, right... not the most obvious case though for let-polymorphism.
A perhaps more talking example would be
let f x = x in (f 1, f "1")
While let-polymorphism makes obvious sense when using f as a function,
it's less intuitive when it used on a function argument such as [],
though quite logical.
Personnally, I find it quite weird to have the value restriction on list
refs, but not on lists:
# let x = [];;
val x : 'a list = []
# let x = ref [];;
val x : '_a list ref = {contents = []}
# let x = [] in (List.map print_string x), (List.map print_int x);;
- : unit list * unit list = ([], [])
# let x = ref [] in (List.map print_string !x), (List.map print_int !x);;
Error: This expression has type string list
but an expression was expected of type int list
Using the print function on a state which doesn't have [] as first
component of the tuple would likely fixate properly the '_a, though.
--
Guillaume Yziquel
next prev parent reply other threads:[~2011-09-03 11:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-03 9:53 Goswin von Brederlow
2011-09-03 10:31 ` Christophe Papazian
2011-09-03 11:42 ` Guillaume Yziquel [this message]
2011-09-03 10:36 ` Guillaume Yziquel
2011-09-03 11:35 ` Philippe Veber
2011-09-03 11:46 ` Guillaume Yziquel
2011-09-03 12:15 ` Gabriel Scherer
2011-09-03 12:50 ` Guillaume Yziquel
2011-09-17 12:08 ` Goswin von Brederlow
2011-09-18 7:26 ` Gabriel Scherer
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=20110903114214.GZ15100@localhost \
--to=guillaume.yziquel@citycable.ch \
--cc=caml-list@inria.fr \
--cc=christophe.papazian@gmail.com \
--cc=goswin-v-b@web.de \
/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