caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Mike Potanin <potanin@mccme.ru>
To: caml-list@inria.fr
Subject: [Caml-list] Re: your mail
Date: Fri, 7 Feb 2003 16:10:23 +0300 (MSK)	[thread overview]
Message-ID: <Pine.LNX.4.44.0302071608300.14579-100000@mccme.ru> (raw)
In-Reply-To: <DAV40GzGqiuLeHTgzW20001670e@hotmail.com>

On Thu, 6 Feb 2003, Nikolaj Bjorner wrote:

> I am pretty sure this is not related to references, but to let-rec.
>
> Try:
>
> let rec f x = x and g y = f y + 1;;
>
> you will see that the type inferred is:
>
> val f : int -> int
> val g : int -> int
>
> Now try:
>
> let f x = x and g y = f y + 1;;
      ^                 ^
This is different functions. First "f" defined new function. Second "f"
referred to old function "f".

>
> this time:
>
> val f : 'a -> 'a
> val g : int -> int
>
> You may still be wondering why, of course.
> The basic answer (I hope I am not too rusty in this)
> is that type inference for polymorphic let-rec is not decidable
> (you have to solve a semi-unification problem).
> Hence, the "solution" is not to abstract type variables
> until all type inference for all
> let-rec-and clauses have been analyzed.
>
> So:
>
> let rec f x = x and g y = f y + 1 and h z = not (h z);;
>
> does not type check at all, but again:
> let f x = x and g y = f y + 1 and h z = not (h z);;
> does work.
>
>
> Nikolaj
>
>
>
>
> From: Chris Hecker [mailto:checker@d6.com]
> Sent: Thu 2/6/2003 5:31 PM
> To: caml-list@inria.fr
> Subject: [Caml-list] streams and value restriction
>
>
>
>
> I assume I'm running into the polymorphism restriction thing here, but
> I'm not sure why (I kind of understand it when references are in play,
> but this is baffling me).
>
> Here's a simple version of some stream parser code.  I'd like
> parse_opt_comma_list to be polymorphic so I can use it to parse lists
> of any of my values.  It works fine as a separate let rec, but if I
> put it in the overall let rec of the main parser (with and) it won't
> generalize and gets tagged as string-only since that's the first way
> it's used.
>
> Can somebody explain why this is a problem?  Sorry for being dense.
>
> Thanks,
> Chris
>
>
> type t =
>     Int of int
>   | String of string
>
> (* this works: *)
> let rec parse_opt_comma_list parse list = parser
>     [< 'Genlex.Kwd ",";
>        a = parse ;
>        optlist = parse_opt_comma_list parse (a::list) >] -> optlist
>   | [< >] -> list
>
> let rec parse_values = parser
>     [< 'Genlex.String s;
>        optlist = parse_opt_comma_list (parser [< 'Genlex.String s >] -> s) [] >] ->
>          (String s) :: List.map (fun s -> String s) optlist
>   | [< 'Genlex.Int i;
>        optlist = parse_opt_comma_list (parser [< 'Genlex.Int i >] -> i) [] >] ->
>          (Int i) :: List.map (fun i -> Int i) optlist
>
> (* this doesn't: *)
> let rec parse_values = parser
>     [< 'Genlex.String s;
>        optlist = parse_opt_comma_list (parser [< 'Genlex.String s >] -> s) [] >] ->
>          (String s) :: List.map (fun s -> String s) optlist
>   | [< 'Genlex.Int i;
>        optlist = parse_opt_comma_list (parser [< 'Genlex.Int i >] -> i) [] >] ->
>          (Int i) :: List.map (fun i -> Int i) optlist
>
> and parse_opt_comma_list parse list = parser
>     [< 'Genlex.Kwd ",";
>        a = parse ;
>        optlist = parse_opt_comma_list parse (a::list) >] -> optlist
>   | [< >] -> list
>
>
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2003-02-07 12:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-07  5:23 Nikolaj Bjorner
2003-02-07 13:10 ` Mike Potanin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-01-21 23:27 cgillot
2002-01-21 22:43 ` [Caml-list] Re: your mail Markus Mottl
2002-01-22  9:00   ` Daniel de Rauglaudre
2002-01-22 13:12     ` Markus Mottl
2001-08-03 10:58 Johann Spies
2001-08-03 13:26 ` [Caml-list] Re: your mail Francois Pottier
2001-08-03 17:42 ` Vitaly Lugovsky
2001-03-06 20:25 rakesh malhotra
2001-03-07 16:53 ` [Caml-list] Re: your mail Brian Rogoff

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=Pine.LNX.4.44.0302071608300.14579-100000@mccme.ru \
    --to=potanin@mccme.ru \
    --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).