Skip to content

Unexpected interaction between variance and GADTs #5985

@vicuna

Description

@vicuna

Original bug ID: 5985
Reporter: @yallop
Assigned to: @garrigue
Status: confirmed (set by @garrigue on 2013-04-13T11:46:07Z)
Resolution: open
Priority: normal
Severity: feature
Target version: later
Category: typing
Tags: patch
Related to: #6275 #7360
Child of: #5984 #5998
Monitored by: @lpw25 mcclurmc @glondu @dra27 @alainfrisch @diremy

Bug description

The following program

type _ t = T : 'a -> 'a s t

is accepted if s is covariant (e.g. type 'a s = 'a), contravariant (e.g. type 'a s = 'a -> unit) or invariant (e.g. type 'a s = 'a -> 'a), but rejected if s is "bivariant" (e.g. type 'a s = int):

# type 'a s = int;;
type 'a s = int
# type _ t = T : 'a -> 'a s t ;;
Characters 4-27:
  type _ t = T : 'a -> 'a s t ;;
      ^^^^^^^^^^^^^^^^^^^^^^^
Error: In this definition, a type variable has a variance that
       is not reflected by its occurrence in type parameters.

However, if s is abstracted then the program is accepted, even if s is instantiated with a bivariant constructor:

# include
  (functor (S : sig type 'a s end) ->
    struct
      include S
      type _ t = T : 'a -> 'a s t
    end)
    (struct type 'a s = int end)
;;
type 'a s = int
type _ t = T : 'a -> 'a s t
#

File attachments

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions