# Syntax error when using record type in sharing constraint

**URL:** <https://discuss.ocaml.org/t/syntax-error-when-using-record-type-in-sharing-constraint/3149>\
**Category:** Learning\
**Created:** [January 11, 2019, 9:39pm UTC](https://discuss.ocaml.org/t/syntax-error-when-using-record-type-in-sharing-constraint/3149 "2019-01-11T21:39:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![voidc](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@voidc](https://discuss.ocaml.org/u/voidc)\
**Post date:** [January 11, 2019, 9:39pm UTC](https://discuss.ocaml.org/t/syntax-error-when-using-record-type-in-sharing-constraint/3149/1 "2019-01-11T21:39:01Z")

</div>

Consider the following example:

```
module type A = sig type t end
module B : A with type t = { key : int } = struct type t = { key : int } end

```

This code will not compile but produce a syntax error at the opening curly brace of the sharing constraint.  
A workaround is to extract the record type into a separate new type and using that instead. However I do wonder why the example above is rejected by the compiler and would be glad if anybody could explain.

---

<div class="post-metadata">

**Author:** ![Juloo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/juloo/32/881_2.png) [@Juloo](https://discuss.ocaml.org/u/Juloo)\
**Post date:** [January 11, 2019, 10:37pm UTC](https://discuss.ocaml.org/t/syntax-error-when-using-record-type-in-sharing-constraint/3149/2 "2019-01-11T22:37:29Z")

</div>

This is because curly braces are only valid when declaring a record type `type t = { }` and not in the “type” language, you cannot write `let x : { key : int } = ...`

---

<div class="post-metadata">

**Author:** ![bcc32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bcc32/32/203_2.png) [@bcc32](https://discuss.ocaml.org/u/bcc32)\
**Post date:** [January 11, 2019, 11:23pm UTC](https://discuss.ocaml.org/t/syntax-error-when-using-record-type-in-sharing-constraint/3149/3 "2019-01-11T23:23:35Z")

</div>

You could try writing the following instead:

```ocaml
module type A = sig
  type t
end

type t_record = { key : int }

module B : A with type t = t_record = struct
  type t = t_record = { key : int }
end

```

---

<div class="post-metadata">

**Author:** ![RogerT](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@RogerT](https://discuss.ocaml.org/u/RogerT)\
**Post date:** [January 12, 2019, 6:05am UTC](https://discuss.ocaml.org/t/syntax-error-when-using-record-type-in-sharing-constraint/3149/4 "2019-01-12T06:05:23Z")

</div>

I’m still learning the subtleties of the module system. So can you tell us a little bit more about your use case and the interest of writing a concrete type in the signature of module B that is the same as the type of its structure? (while, in general, we should have an abstract type for a module signature and choose some relevant concrete type for the structure).
