caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: checker@d6.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] streams and value restriction
Date: Fri, 07 Feb 2003 16:36:34 +0900	[thread overview]
Message-ID: <20030207163634D.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <200302070131.h171VJu24020@plinky.bolt-action.com>

From: Chris Hecker <checker@d6.com>

> 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


      reply	other threads:[~2003-02-07  7:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-07  1:31 Chris Hecker
2003-02-07  7:36 ` Jacques Garrigue [this message]

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=20030207163634D.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=checker@d6.com \
    /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).