caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: ygrek <ygrek@autistici.org>
To: caml-list@inria.fr
Subject: [Caml-list] They have different arities
Date: Tue, 4 Jul 2017 01:21:22 -0700	[thread overview]
Message-ID: <20170704012122.71fe4a55@kiwi.local.tld> (raw)

Hello,

Consider the following : 
```
# type t' = int option;;
type t' = int option
# type t = int option = None | Some of int;;
Characters 0-40:
  type t = int option = None | Some of int;;
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This variant or record definition does not match that of type
         int option
       They have different arities.
```

What is the reasoning behind this error?
I was expecting "specialisation" (in C++ terms), i.e. after `'a` in `'a option` was substituded for `int` -
type is now 0-arity and equality should hold - there is no "free" arity left..
     
I gather that in case of `t'` it is type abbreviation and for `t` it is a re-export. The manual says :
 
> Re-exported variant type or record type: an equation, a representation.
>    In this case, the type constructor is defined as an abbreviation for the type expression given in the equation, but in addition the constructors or fields given in the representation remain attached to the defined type constructor. The type expression in the equation part must agree with the representation: it must be of the same kind (record or variant) and have exactly the same constructors or fields, in the same order, with the same arguments. 

So it seems as long as representation matches - `t` should behave the same as abbreviation `t'`.

PS The real-world usage for this involves a bigger type and a need to define serialization function for a "specialized" type outside of module with generic definition, hence the requirement to explicitly list constructors by re-exporting, but type has to be monomorphic.

-- 

             reply	other threads:[~2017-07-04  8:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-04  8:21 ygrek [this message]
2017-07-04  9:15 ` Josh Berdine
2017-07-06  5:50   ` ygrek

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=20170704012122.71fe4a55@kiwi.local.tld \
    --to=ygrek@autistici.org \
    --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).