caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Arnaud Spiwack <Arnaud.Spiwack@lix.polytechnique.fr>
To: Richard Jones <rich@annexia.org>
Cc: Antoine Delignat-Lavaud
	<antoine.delignat-lavaud@dptinfo.ens-cachan.fr>,
	caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Why does value restriction not apply to the empty list ?
Date: Sat, 10 Jan 2009 14:10:38 +0100	[thread overview]
Message-ID: <49689E4E.5000300@lix.polytechnique.fr> (raw)
In-Reply-To: <20090110125925.GA6231@annexia.org>


> It's a strange one ... when the if statement appears as a toplevel
> statement, OCaml infers the type 'a list for the list:
>   
It is not anyhow strange, it is how OCaml always does. It generalises 
types of variables introduced by a let (or equivalently at toplevel), 
types of other variables are not polymorphic.

In the case of list it should be fairly clear, by the way, that the 
empty list is the only one that has type 'a list for all 'a.
> # let el = [] ;;
> val el : 'a list = []
> # if List.length el > 0 then (List.hd el)+(int_of_string (List.hd el)) else 0;;
> - : int = 0
> # el ;;
> - : 'a list = []
>
> But the same if statement within a function definition causes an error:
>
> # let f el =            
>   if List.length el > 0 then (List.hd el)+(int_of_string (List.hd el)) else 0;;
>                                                           ^^^^^^^^^^
> This expression has type int but is here used with type string
>
> Rich.
>
>   


  reply	other threads:[~2009-01-10 13:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-10 11:34 Antoine Delignat-Lavaud
2009-01-10 12:59 ` [Caml-list] " Richard Jones
2009-01-10 13:10   ` Arnaud Spiwack [this message]
     [not found] ` <527cf6bc0901100556n40b54b0amff84a7707aacb0ae@mail.gmail.com>
2009-01-10 17:48   ` Antoine Delignat-Lavaud
2009-01-11 16:31 ` Xavier Leroy

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=49689E4E.5000300@lix.polytechnique.fr \
    --to=arnaud.spiwack@lix.polytechnique.fr \
    --cc=antoine.delignat-lavaud@dptinfo.ens-cachan.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=rich@annexia.org \
    /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).