caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: Guillaume Yziquel <guillaume.yziquel@citycable.ch>,
	Philippe Veber <philippe.veber@gmail.com>,
	Goswin von Brederlow <goswin-v-b@web.de>,
	caml-list@inria.fr
Subject: Re: [Caml-list] Odd failure to infer types
Date: Sat, 17 Sep 2011 14:08:28 +0200	[thread overview]
Message-ID: <87bouj2wxv.fsf@frosties.localnet> (raw)
In-Reply-To: <CAPFanBFbX-D_hb0SqXS7-g3cG9RVe6-W3MzEs_FvfwqRhX54aA@mail.gmail.com> (Gabriel Scherer's message of "Sat, 3 Sep 2011 14:15:35 +0200")

Gabriel Scherer <gabriel.scherer@gmail.com> writes:

> Indeed, a let-bound [] is generalized to a polymorphic ('a list), while a
> let-bound (ref []), or (Array.make n []), is not generalized. It would be
> unsound to do so as if you had a reference to a polymorphic ('a list) you could
> add elements of different types in the list.
>
> When a type variable is not generalized (polymorphic), it stays an "unknown" of
> the type system until it is unified to a known type:
>
> # let r = ref [];;
> val r : '_a list ref = {contents = []}
> # r := 1 :: !r;;
> - : unit = ()
> # r;;
> - : int list ref = {contents = [1]}
>
> '_a is sometimes called a "weakly polymorphic variable", in fact it is not
> polymorphic at all. It is just an unknown.
>
> In the code example above, the real type for '_a could be determined after two
> phrases in the top level. It may also happen as a compilation unit (if the code
> was written in a file instead of fed phrase-per-phrase to the toplevel). We
> wouldn't observe the intermediary '_a inferred type, as the type are inferred
> globally.

I think you are missing the point.

I totaly get why it must be '_a instead if 'a. My question is why it
doesn't infer the full type from the call to the print function.

In my case the type inferences outputs something like this (using the
above example):

> # let r = ref [];;
> val r : '_a list ref = {contents = []}
> # r := 1 :: !r;;
> - : unit = ()
> # r;;
> - : '_a list ref = {contents = [1]}

I see my print call as equivalent to '1 :: !r'.

MfG
        Goswin

  parent reply	other threads:[~2011-09-17 12:08 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
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 [this message]
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=87bouj2wxv.fsf@frosties.localnet \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    --cc=gabriel.scherer@gmail.com \
    --cc=guillaume.yziquel@citycable.ch \
    --cc=philippe.veber@gmail.com \
    /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).