From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Aaron Gray <aaronngray.lists@gmail.com>
Cc: Mailing List OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] coinductive data types
Date: Thu, 1 Sep 2022 21:13:19 +0900 [thread overview]
Message-ID: <EF040188-CBD8-4CDA-A0B2-CD3E2062B9F7@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CANkmNDcbpxy_di58RCuH08agO-8qB9A=EUtRFZL9=PC4W9nqtw@mail.gmail.com>
Hi Aaron,
No, there is no physical coercion involved.
Polymorphic variants have a uniform representation of constructor tags
(through a hashing function) so that (`Cons(1, lazy `Nil)) has always the same
representation, be it as int seqc or int aseqc.
So we are just talking about the different types the same value can be given.
Jacques
> 2022/08/31 12:22、Aaron Gray <aaronngray.lists@gmail.com>のメール:
>
> Jacques,
>
> I will get a raw OCaML Docker image, and have a play with this.
>
> What is going on there, does ':>' return a conversion function as well
> as being 'true' and secondly a predicate ?
>
> Thanks,
>
> Aaron
>
>
>
> On Wed, 31 Aug 2022 at 02:15, Jacques Garrigue
> <jacques.garrigue@gmail.com> wrote:
>>
>> Hello Aaron,
>>
>> If you are interested in the subtyping already available inside OCaml,
>> it provides width subtyping for both objects and polymorphic variants.
>> Polymorphic variants are algebraic datatypes, but their equality is
>> structural rather than nominal, and they are limited to regular type
>> definitions.
>>
>> For instance, the following subtyping on two variants of potentially infinite
>> streams is available:
>>
>> type 'a seq = 'a seqc lazy_t and 'a seqc = [`Nil | `Cons of 'a * 'a seq]
>> type 'a aseq = 'a aseqc lazy_t
>> and 'a aseqc = ['a seqc | `App of 'a aseq * 'a aseq]
>> let sub x = (x : 'a seq :> 'a aseq)
>> (* val sub : 'a seq -> 'a aseq *)
>>
>> Jacques Garrigue
>>
>> 2022/08/30 21:33、Aaron Gray <aaronngray.lists@gmail.com>のメール:
>>
>> On Tue, 30 Aug 2022 at 12:12, Xavier Leroy
>> <xavier.leroy@college-de-france.fr> wrote:
>>
>>
>> On Tue, Aug 30, 2022 at 9:24 AM François Pottier <francois.pottier@inria.fr> wrote:
>>
>>
>>
>> Hello,
>>
>> Le 29/08/2022 à 17:43, Aaron Gray a écrit :
>>
>> Does either ML or OCaML have coinductive data types ? And if so could
>> you please point me at the/some appropriate documentation on them.
>>
>>
>> ML and OCaml have algebraic data types, which are recursive (that is,
>> more general than inductive and co-inductive types). Algebraic data
>> type definitions are not subject to a positivity restriction, and
>> algebraic data types can be constructed and deconstructed by recursive
>> functions, which are not subject to a termination check.
>>
>>
>> Hello Xavier,
>>
>> Thanks for putting me straight on that.
>>
>> My original path of inquiry which I should have actually stated was
>> regarding how to go about implementing subtyping of mutually recursive
>> algebraic data types.
>>
>> I am looking on how to go about this and using coinduction and
>> bisimulation seemed like the best fit or correct way to go about this.
>>
>> Does OCaML use/handle subtyping of mutually recursive algebraic data
>> types ? And if so, is its implementation easily accessible ?
>>
>> If you want to see a typical example of a "co-inductive" data structure
>> encoded in OCaml, I suggest to have a look at "sequences", which can be
>> described as potentially infinite lists:
>>
>> https://v2.ocaml.org/api/Seq.html
>>
>> Lazy evaluation (type Lazy.t) can also be used to define coinductive data structures.
>>
>> For concreteness, here are two definitions of the type of streams (infinite lists) :
>>
>> type 'a stream = unit -> 'a streamcell and 'a streamcell = { head: 'a; tail: 'a stream }
>> type 'a stream = 'a streamcell Lazy.t and 'a streamcell = { head: 'a; tail: 'a stream }
>>
>> and of the stream of integers starting from n :
>>
>> let rec ints n = fun () -> { head = n; tail = ints (n + 1) }
>> let rec ints n = lazy { head = n; tail = ints (n + 1) }
>>
>>
>> Thank you, yes I am familiar with this type of usage.
>>
>> Regards,
>>
>> Aaron
>>
>>
>>
>> Hope this helps,
>>
>> - Xavier Leroy
>>
>>
>>
>> --
>> François Pottier
>> francois.pottier@inria.fr
>> http://cambium.inria.fr/~fpottier/
>>
>>
>>
>>
>> --
>> Aaron Gray
>>
>> Independent Open Source Software Engineer, Computer Language
>> Researcher, Information Theorist, and amateur computer scientist.
>>
>>
>
>
> --
> Aaron Gray
>
> Independent Open Source Software Engineer, Computer Language
> Researcher, Information Theorist, and amateur computer scientist.
next prev parent reply other threads:[~2022-09-01 12:13 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-29 15:43 Aaron Gray
2022-08-30 7:24 ` François Pottier
2022-08-30 11:11 ` Xavier Leroy
2022-08-30 12:33 ` Aaron Gray
2022-08-31 1:21 ` Jacques Garrigue
[not found] ` <11E3A59A-BD33-4EC0-9FAD-711A1EACA35E@gmail.com>
2022-08-31 3:22 ` Aaron Gray
2022-09-01 12:13 ` Jacques Garrigue [this message]
2022-08-30 12:37 ` Aaron Gray
2022-08-30 13:57 ` Nate Foster
2022-08-30 15:27 ` Aaron Gray
2022-08-30 15:47 ` François Pottier
2022-08-30 16:32 ` Aaron Gray
2022-08-31 8:19 ` François Pottier
2022-08-30 16:45 ` Andreas Rossberg
2022-08-30 17:01 ` Aaron Gray
2022-08-30 18:20 ` Nate Foster
2022-08-31 8:25 ` François Pottier
2022-08-31 8:46 ` Peter Thiemann
2022-08-31 9:41 ` Andreas Rossberg
2022-08-31 13:49 ` François Pottier
2022-08-31 15:40 ` Peter Thiemann
2022-08-31 16:44 ` Andreas Rossberg
2022-08-31 15:55 ` Basile Clement
2022-08-31 18:42 ` Andreas Rossberg
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=EF040188-CBD8-4CDA-A0B2-CD3E2062B9F7@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=aaronngray.lists@gmail.com \
--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