Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "François Pottier" <francois.pottier@inria.fr>
To: Aaron Gray <aaronngray.lists@gmail.com>
Cc: OCaML Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] coinductive data types
Date: Tue, 30 Aug 2022 17:47:40 +0200	[thread overview]
Message-ID: <8078ad33-f220-b233-4863-06ce30cc8cff@inria.fr> (raw)
In-Reply-To: <CANkmNDeFiieWNq0WEh0p52E61qHUJ2_BMH8int67uif+RrRAQw@mail.gmail.com>


Hi,

On 30/08/2022 14:37, Aaron Gray wrote:
 > 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.

Do you mean implementing an algorithm that decides whether two types are
related by subtyping, in the presence of mutually recursive algebraic
data types?

I guess the answer depends on exactly how the subtying relation is defined.
E.g., if "α foo" and "β bar" are (parameterized) algebraic data types, does
the subtyping relation "α foo ≤ β bar" necessarily imply that "foo" and 
"bar"
are the same algebraic data type?

- If the answer is positive, then the problem boils down to deciding
   "α ≤ β" or "β ≤ α" or neither or both, depending on whether this
   algebraic data type is covariant or contravariant or neither or both.
   In that case, you are working with "isorecursive" types,
   also known as "nominal" types.

- If the answer is negative, then (I imagine) you wish to unfold the
   definitions of "foo" and "bar" and decide whether the two unfoldings
   are related by subtyping.
   In that case, you are working with "equirecursive" types,
   also known as "structural" types.

Brandt and Henglein ("Coinductive axiomatization of recursive type equality
and subtyping", 1998) study the second problem, if I remember correctly.

 > Does OCaML use/handle subtyping of mutually recursive algebraic data
 > types ? And if so, is its implementation easily accessible ?

OCaml has explicit subtyping coercions: a user can write `(e : t1 :> t2)`
and the compiler will check that `t1` is a subtype of `t2`.

As far as algebraic data types are concerned, OCaml's notion of subtyping is
nominal, I believe. An algebraic data type can be decorated with variance
annotations, so, for instance, "list" can be declared covariant and "α list"
is considered a subtype of "β list" if α is a subtype of β. However, "α 
list"
can never be considered a subtype of an algebraic data type other than 
"list".

The variance annotations provided by the programmer are checked when an
algebraic data type is defined, and are later used when deciding whether a
subtyping relation holds.

Some more information here:

   https://blog.janestreet.com/a-and-a/
   https://v2.ocaml.org/manual/expr.html#ss%3Aexpr-coercions

--
François Pottier
Francois.Pottier@inria.fr
http://cambium.inria.fr/~fpottier/

  parent reply	other threads:[~2022-08-30 15:47 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
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 [this message]
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=8078ad33-f220-b233-4863-06ce30cc8cff@inria.fr \
    --to=francois.pottier@inria.fr \
    --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