caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Mr. Herr" <misterherr@freenet.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Cyclic type abbreviation
Date: Fri, 13 Nov 2015 14:53:29 +0100	[thread overview]
Message-ID: <5645EB59.8040505@freenet.de> (raw)
In-Reply-To: <E51C5B015DBD1348A1D85763337FB6D9EA03E44B@Remus.metastack.local>



On 13.11.2015 14:37, David Allsopp wrote:
> Mr. Herr wrote:
>> On 13.11.2015 13:49, Christoph Höger wrote:
>>> Dear all,
>>>
>>> why is this type cyclic?
>>>
>>> type node = int * tree * tree
>>>  and tree = node option
>>>
>>> I cannot introduce a manifest for the option type, as there is no
>>> Option module (why is that, btw?) - so I would assume option to be
>>> special enough to be handled like any other algebraic data type.
>> type 'a option = None | Some 'a
>>
>> no need for a module, just a simple type. Maybe you confound it with other
>> languages.
>>
>> And cyclic - well, the types are referring to each other.
>>
>> Summary: what is supposedly wrong with it?
> I expect that what is wrong is that you can write:
>
> type node = int * tree * tree
>  and tree = Some of node
>           | None
>
> I don't know why you can't write [and tree = node option] instead.
>
>
>
Ah, did not see the problem at first sight...

Maybe that is why people so often define their own empty element:

# type node = Emptynode | Node of (int * node * node) ;;
type node = Emptynode | Node of (int * node * node)

# type node = Emptynode | Node of int * node * node ;; (* just had this parens
discussion... *)
type node = Emptynode | Node of int * node * node


/Str.


      parent reply	other threads:[~2015-11-13 13:56 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
2015-11-13 13:46     ` Christoph Höger
2015-11-13 13:53     ` Mr. Herr [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=5645EB59.8040505@freenet.de \
    --to=misterherr@freenet.de \
    --cc=caml-list@inria.fr \
    /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).