caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: brogoff <brogoff@speakeasy.net>
To: skaller <skaller@users.sourceforge.net>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] cyclic types
Date: Sat, 29 Jan 2005 22:46:38 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.58.0501292229480.12148@shell3.speakeasy.net> (raw)
In-Reply-To: <1107032560.23562.527.camel@pelican.wigram>

On Sat, 30 Jan 2005, skaller wrote:
> On Sun, 2005-01-30 at 04:12, brogoff wrote:
> > This comes up relatively frequently, and it is known that having -rectypes
> > as the default is not a good idea. However, wouldn't explicit typing of
> > this case sidestep the known problems and eliminate the need for a
> > -rectypes option here?
>
> Do you mean something like:
>
> 	type rec forest = forest StringMap.t
>
> where the 'rec' means 'just this type is meant to be cyclic'
> (and treat that type as if -rectypes had been given)?

No, I meant just accept the cyclic types as we do now with -rectypes, but
annotate the functions that use them, something like this (pseudo OCaml)

type ('a, 'b) t = 'a * (('a , 'b) t -> 'b) list

let foo : 'a -> (('a * ('b -> 'c) list as 'b) -> 'c = fun n m ->
    (List.assoc n m) m

Nice huh, the type is longer than the actual code :-(. Anyways, I rememeber
someone complaining about the overhead of the connstructor wrapping in order to
do this in real OCaml (that is, without -rectypes) and this does away with that.

If it were just cyclic types, it wouldn't be a big deal, but there are other
places that explicit types driving the typing could pay off. There are a couple
of ways to  get nonuniform recursion in OCaml but (with the exception of perhaps
the *experimental* recursive module feature) they're clunky workarounds. The
right way is just to annotate the functions with their types.

-- Brian


      reply	other threads:[~2005-01-30  6:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-29 12:15 Radu Grigore
2005-01-29 12:34 ` Radu Grigore
2005-01-29 13:42 ` [Caml-list] " Remi Vanicat
2005-01-29 17:12   ` brogoff
2005-01-29 17:33     ` Radu Grigore
2005-01-29 23:47       ` Damien Doligez
2005-01-30  5:56         ` brogoff
2005-01-30  6:05         ` Radu Grigore
2005-01-30  7:19           ` William Lovas
2005-01-30 10:33       ` Xavier Leroy
2005-01-30 11:44         ` sejourne_kevin
2005-02-01  9:27         ` Christophe Raffalli
2005-01-29 21:02     ` skaller
2005-01-30  6:46       ` brogoff [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=Pine.LNX.4.58.0501292229480.12148@shell3.speakeasy.net \
    --to=brogoff@speakeasy.net \
    --cc=caml-list@inria.fr \
    --cc=skaller@users.sourceforge.net \
    /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).