caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pierrick Couderc <pierrick.couderc@ocamlpro.com>
To: peterfrey <pjfrey@sympatico.ca>, devel+inria@ocamlpro.com
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Cyclic type abbreviation
Date: Mon, 16 Nov 2015 18:08:35 +0100	[thread overview]
Message-ID: <CA+gYG2vMoyorD0Q6n-RHhyFksW5SGzDdTZmiRzSdBy6SrZW+Jw@mail.gmail.com> (raw)
In-Reply-To: <564A078B.80309@sympatico.ca>

[-- Attachment #1: Type: text/plain, Size: 2166 bytes --]

Actually, the "type recursivity" is syntactic: if you wrap your recursive
type in a data constructor or a record, there is no cycle in the type.
Using directly 'node option' won't work since syntactically there is no
data constructor to the unfold the type.
We know that the option type is an ADT so we can think that this definition
is correct and does not need the -rectypes flag, but the typechecker will
not infer such a characteristic and decide that, by looking at the type
definition, it is recursive since there is no constructor to fold and
unfold the type.

The only problem by redefining an option type especially for this
definition is that it won't be compatible with the built-in option type.
An idea to overcome this problem would be to be able to use the type
redefinition :

type tree =...
and type node = tree option = Some of tree | None

However, I don't know if it would be possible/sound, and really necessary
without complexifying the language.
Le 16 nov. 2015 5:43 PM, "peterfrey" <pjfrey@sympatico.ca> a écrit :

> Interestingly, this definition is accepted:
>
>>
>> type tree = (int * 'a * 'a) option as 'a
>>
>> Here you are helping the type-checker because you give it a "canonical"
>> representation that it can use when unifying; it no longer has to expand
>> the type, potentially infinitely. I think the main point is that the type
>> is isorecursive, but I'm not really an expert on the subject.
>>
>> with this type-checking business I sometimes have the feel being Alice in
> Wonderland; its getting curiouser and curiouser ...
>
> The type : type node = int * tree * tree  and tree = node option is, in
> fact, accepted if you use the -rectypes option.
> I just checked it with utop -rectypes
>
> I wonder if this is considered bad (dangerous) style; but there are
> several things that would not work for me without this option.
>
> Peter Frey
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 2917 bytes --]

  reply	other threads:[~2015-11-16 17:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-13 12:49 Christoph Höger
2015-11-13 13:15 ` Mr. Herr
2015-11-13 13:37   ` David Allsopp
2015-11-13 13:46     ` Romain Bardou
2015-11-13 14:24       ` Romain Bardou
2015-11-16  5:43         ` Ben Millwood
2015-11-16 16:42       ` peterfrey
2015-11-16 17:08         ` Pierrick Couderc [this message]
2015-11-13 13:46     ` Christoph Höger
2015-11-13 13:53     ` Mr. Herr

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=CA+gYG2vMoyorD0Q6n-RHhyFksW5SGzDdTZmiRzSdBy6SrZW+Jw@mail.gmail.com \
    --to=pierrick.couderc@ocamlpro.com \
    --cc=caml-list@inria.fr \
    --cc=devel+inria@ocamlpro.com \
    --cc=pjfrey@sympatico.ca \
    /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).