caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Angelo Corsaro <angelo@icorsaro.net>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Recursive record initialisation
Date: Tue, 17 Apr 2018 00:07:24 +0300	[thread overview]
Message-ID: <CAPFanBGWvirh+VVBdayEejn34u6W_fQAazrQbzHYY8dWP86WmA@mail.gmail.com> (raw)
In-Reply-To: <A3ACD6F4-5EA8-49C4-9BB7-7C4445F3EB2D@icorsaro.net>

The fact that the declaration is legal does not imply that you can
build useful values at this type. (It may be that trying to reject it
would naturally lead to reject other types that *are* more
interesting, for example.)

In this case you can build a value using value recursion, but it is
not very interesting:

# let rec a = { b }
       and b = { a };;
val a : atype = {b = {a = <cycle>}}
val b : btype = {a = {b = <cycle>}}

( Recursive value definitions:
http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#s%3Aletrecvalues
)

Recursive value definitions are somewhat arcane and rarely used, but
still occasionally useful. One downside is that they prevent a purely
inductive interpretation of datatypes: if a recursive function is
structurally decreasing on one of its argument, there still exists
valid OCaml inputs on which it may not terminate. For example,
consider List.length on (let rec x = 1 :: 2 :: x).

On Mon, Apr 16, 2018 at 11:57 PM, Angelo Corsaro <angelo@icorsaro.net> wrote:
> Hello,
>
> I have a question concerning the initialisation of mutually recursive record
> types. As a trivial example consider the following type declaration:
>
> type atype = { b : btype; }
> and btype = { a : atype; }
>
> This is a legal type declaration (it type-checks w/o a blink), but I can’t
> see how such a type would be initialised? As both “a" and “b” are values
> there is an apparent bootstrapping issue. But as this is a legal type
> declaration I guess there is a way around, wondering what the right way is.
>
> Thanks very much in advance for any clarification.
>
> —Angelo
>
>
>
>
> —
> “Simplicity is the ultimate sophistication." ~ Leonardo da Vinci
>

-- 
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

      reply	other threads:[~2018-04-16 21:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16 20:57 Angelo Corsaro
2018-04-16 21:07 ` Gabriel Scherer [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=CAPFanBGWvirh+VVBdayEejn34u6W_fQAazrQbzHYY8dWP86WmA@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=angelo@icorsaro.net \
    --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).