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 BAA19407; Fri, 7 Feb 2003 01:22:57 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA19618 for ; Fri, 7 Feb 2003 01:22:56 +0100 (MET) Received: from plinky.bolt-action.com (node-d8e9cca3-sfo-onnet.worldcom.com [216.233.204.163]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h170MtP15422 for ; Fri, 7 Feb 2003 01:22:55 +0100 (MET) Received: from CHECKERATH (node-d8e9cca2-sfo-onnet.worldcom.com [216.233.204.162]) by plinky.bolt-action.com (8.11.6/8.9.3) with SMTP id h171VJu24020 for ; Thu, 6 Feb 2003 17:31:24 -0800 Date: Thu, 6 Feb 2003 17:31:24 -0800 Message-Id: <200302070131.h171VJu24020@plinky.bolt-action.com> From: Chris Hecker To: caml-list@inria.fr Subject: [Caml-list] streams and value restriction Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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