8

This is just a test so I'm not much concerned, but I have these definitions:

type z
type _ s
type (_, _, _) balance =
  | Less : (*∀'a.*) ('a, 'a s, 'a s) balance
  | Same : (*∀'b.*) ('b, 'b, 'b) balance
  | More : (*∀'a.*) ('a s, 'a, 'a s) balance
type _ aVL =
  | Leaf : z aVL
  | Node : (*∀'a, 'b, 'c.*)('a, 'b, 'c) balance * 'a aVL * int * 'b aVL ->
    ('c s) aVL

and I get the error for "type _ aVL =":

Error: In this definition, a type variable cannot be deduced
       from the type parameters.

What to do?

lukstafi
  • 1,883
  • 15
  • 22
  • Compiles fine here with ocaml 4.00.1. Which version do you have? – gsg Dec 20 '13 at 03:34
  • 2
    @gsg I have asked on ''caml-list'' and the reason is the treatment of injectivity of types introduced on OCaml 4.01. I'll quote the response as an answer soon (unless GaSche does it first). – lukstafi Dec 20 '13 at 09:02
  • Please do, that sounds like it could be interesting reading. – gsg Dec 20 '13 at 09:25
  • 2
    The paper from the talk they mention is : http://ocaml.org/meetings/ocaml/2013/proposals/injectivity.pdf and the slides : http://ocaml.org/meetings/ocaml/2013/slides/garrigue.pdf – nlucaroni Dec 20 '13 at 14:39

1 Answers1

7

H/T to Gabriel Scherer for answering at caml-list.

Don't use this kind of abstract type definition. Use instead (and export) concrete definitions (even if you don't use their constructors for anything)

type 'a s = S of 'a

(or just type 'a s = S)

They have "better" injectivity properties. We've mentioned in on the mailing-list a couple of time, and it's also the "easy take-away lesson" from Jacques Garrigue talk at the OCaml workshop in September.

Shame on me for not googling for the problem. Here the exact problem is addressed: GADTs : a type variable cannot be deduced

lukstafi
  • 1,883
  • 15
  • 22
  • Is there a reason to not look into type synonym definitions in your own module ? I imagine injectivity could be deduced without a "newtype" – nicolas Apr 22 '21 at 07:36