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 IAA26132; Fri, 7 Feb 2003 08:36:43 +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 IAA25665 for ; Fri, 7 Feb 2003 08:36:42 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h177aeP22987 for ; Fri, 7 Feb 2003 08:36:40 +0100 (MET) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id QAA27661; Fri, 7 Feb 2003 16:36:34 +0900 (JST) To: checker@d6.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] streams and value restriction In-Reply-To: <200302070131.h171VJu24020@plinky.bolt-action.com> References: <200302070131.h171VJu24020@plinky.bolt-action.com> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20030207163634D.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 07 Feb 2003 16:36:34 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Chris Hecker > 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. There are two restrictions to polymorphism. One is the infamous value restriction. But this is not the case here. Another one it that polymorphic values are only generalized after typing a group of recursive definitions. That is, you cannot use a value polymorphically inside the same group of recursive definitions. If you want to do that, you must move your definition out of the group (you found that yourself). This is also true for mutually recursive classes, but no longer for type definitions (their polymorphism is explicit). There are known solutions to this problem (search this list for "polymorphic recursion"), but no general one is implemented in ocaml (general ones are not complete, but some are pretty good). Note that you can use polymorphic recursion between methods in a class (using polymorphic methods), but this is a bit far-fetched for your problem. Jacques Garrigue ------------------- 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