From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA01053; Fri, 7 Feb 2003 13:38:06 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA01390 for caml-list@pauillac.inria.fr; Fri, 7 Feb 2003 13:38:05 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA24206 for ; Fri, 7 Feb 2003 06:22:49 +0100 (MET) Received: from hotmail.com (dav40.pav3.hotmail.com [64.4.38.144]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h175Mkf04708 for ; Fri, 7 Feb 2003 06:22:47 +0100 (MET) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Thu, 6 Feb 2003 21:22:44 -0800 X-Originating-IP: [12.212.86.241] From: "Nikolaj Bjorner" To: Cc: Date: Thu, 6 Feb 2003 21:23:00 -0800 MIME-Version: 1.0 X-Mailer: MSN Explorer 7.02.0011.2700 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0002_01C2CE25.ED24D100" Message-ID: X-OriginalArrivalTime: 07 Feb 2003 05:22:44.0745 (UTC) FILETIME=[F1BD9790:01C2CE68] Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk ------=_NextPart_001_0002_01C2CE25.ED24D100 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am pretty sure this is not related to references, but to let-rec. Try: let rec f x =3D x and g y =3D f y + 1;; you will see that the type inferred is: val f : int -> int val g : int -> int Now try: let f x =3D x and g y =3D f y + 1;; 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) =20 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 =20 until all type inference for all =20 let-rec-and clauses have been analyzed. So: let rec f x =3D x and g y =3D f y + 1 and h z =3D not (h z);; does not type check at all, but again: =20 let f x =3D x and g y =3D f y + 1 and h z =3D 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 =3D Int of int | String of string (* this works: *) let rec parse_opt_comma_list parse list =3D parser [< 'Genlex.Kwd ","; a =3D parse ; optlist =3D parse_opt_comma_list parse (a::list) >] -> optlist | [< >] -> list let rec parse_values =3D parser [< 'Genlex.String s; optlist =3D parse_opt_comma_list (parser [< 'Genlex.String s >] ->= s) [] >] -> (String s) :: List.map (fun s -> String s) optlist | [< 'Genlex.Int i; optlist =3D 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 =3D parser [< 'Genlex.String s; optlist =3D parse_opt_comma_list (parser [< 'Genlex.String s >] ->= s) [] >] -> (String s) :: List.map (fun s -> String s) optlist | [< 'Genlex.Int i; optlist =3D 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 =3D parser [< 'Genlex.Kwd ","; a =3D parse ; optlist =3D parse_opt_comma_list parse (a::list) >] -> optlist | [< >] -> list ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inr= ia.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 ------=_NextPart_001_0002_01C2CE25.ED24D100 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I am pretty sure this is not= related to references, but to let-rec.
 
Try:
 
let rec f= x =3D x and g y =3D f y + 1;;
 
you will see that the type inferred is:
 
val f : int -> int
val g : int -> int
 
Now try:
 
let= f x =3D x and g y =3D f y + 1;;
 
this time:
<= /FONT> 
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 de= cidable
(you have= to solve a semi-unification problem).
Hence, the "solution" is not to abstract type varia= bles 
until = all type inference for all
let-rec-and clauses have been analyzed.
 
= So:
 
let rec f x =3D x and g y =3D f y + 1 and h z =3D not (h z);;=
 
does not type check at all, but&n= bsp;again:

let f x =3D x and g y =3D = f y + 1 and h z =3D not (h z);;

does wor= k.


Nikolaj


From: Chr= is Hecker [mailto:checker@d6.com]
Sent: Thu 2/6/2003 5:31 PMTo: caml-list@inria.fr
Subject: [Caml-list] streams and= value restriction


I ass= ume 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 pars= er code.  I'd like
parse_opt_comma_list to be polymorphic so I ca= n 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 p= arser (with and) it won't
generalize and gets tagged as string-only si= nce that's the first way
it's used.

Can somebody explain why th= is is a problem?  Sorry for being dense.

Thanks,
Chris
=

type t =3D
    Int of int
  | String of= string

(* this works: *)
let rec parse_opt_comma_list parse li= st =3D parser
    [< 'Genlex.Kwd ",";
  = ;     a =3D parse ;
     =   optlist =3D parse_opt_comma_list parse (a::list) >] -> optli= st
  | [< >] -> list

let rec parse_values =3D par= ser
    [< 'Genlex.String s;
   &n= bsp;   optlist =3D parse_opt_comma_list (parser [< 'Genlex.S= tring s >] -> s) [] >] ->
     &n= bsp;   (String s) :: List.map (fun s -> String s) optlist  | [< 'Genlex.Int i;
       op= tlist =3D 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 =3D parser
    [< 'Genlex.Strin= g s;
       optlist =3D parse_opt_comma_= list (parser [< 'Genlex.String s >] -> s) [] >] ->
&nbs= p;        (String s) :: List.map (fun = s -> String s) optlist
  | [< 'Genlex.Int i;
  = ;     optlist =3D parse_opt_comma_list (parser [< = 'Genlex.Int i >] -> i) [] >] ->
    &n= bsp;    (Int i) :: List.map (fun i -> Int i) optlist
and parse_opt_comma_list parse list =3D parser
   = [< 'Genlex.Kwd ",";
       a =3D par= se ;
       optlist =3D parse_opt_comma_= list parse (a::list) >] -> optlist
  | [< >] -> li= st


-------------------
To unsubscribe, mail caml-list-reque= st@inria.fr Archives: http://caml.inria= .fr
Bug reports: ht= tp://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/o= caml_beginners

------=_NextPart_001_0002_01C2CE25.ED24D100-- ------------------- 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