Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top