caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] They have different arities
@ 2017-07-04  8:21 ygrek
  2017-07-04  9:15 ` Josh Berdine
  0 siblings, 1 reply; 3+ messages in thread
From: ygrek @ 2017-07-04  8:21 UTC (permalink / raw)
  To: caml-list

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.

-- 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] They have different arities
  2017-07-04  8:21 [Caml-list] They have different arities ygrek
@ 2017-07-04  9:15 ` Josh Berdine
  2017-07-06  5:50   ` ygrek
  0 siblings, 1 reply; 3+ messages in thread
From: Josh Berdine @ 2017-07-04  9:15 UTC (permalink / raw)
  To: ygrek, caml-list

On Tue, Jul 04 2017, ygrek wrote:

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

As a workaround, is it feasible for you to do the re-export and instantiation in separate steps?
```
type 'a t' = 'a option = None | Some of 'a
type t = int t'
```

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] They have different arities
  2017-07-04  9:15 ` Josh Berdine
@ 2017-07-06  5:50   ` ygrek
  0 siblings, 0 replies; 3+ messages in thread
From: ygrek @ 2017-07-06  5:50 UTC (permalink / raw)
  To: Josh Berdine; +Cc: caml-list

On Tue, 04 Jul 2017 10:15:06 +0100
Josh Berdine <josh@berdine.net> wrote:

> As a workaround, is it feasible for you to do the re-export and instantiation in separate steps?
> ```
> type 'a t' = 'a option = None | Some of 'a
> type t = int t'
> ```

Indeed, this will work. Thanks!
Still original error looks puzzling :)

-- 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-07-06  5:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-04  8:21 [Caml-list] They have different arities ygrek
2017-07-04  9:15 ` Josh Berdine
2017-07-06  5:50   ` ygrek

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