Skip to content

"type ... and ..." is not commutative #3601

@vicuna

Description

@vicuna

Original bug ID: 3601
Reporter: administrator
Assigned to: @garrigue
Status: closed (set by @garrigue on 2010-04-30T06:28:04Z)
Resolution: fixed
Priority: normal
Severity: feature
Fixed in version: 3.12.0+dev
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Francois Pottier
Version: 3.08+alpha1 (2004-07-03)
OS: RedHat Linux 8
Submission from: madiran.inria.fr (128.93.8.77)

Mutually recursive data type definitions, written using "type ... and ...",
are not commutative, even though one might expect them to be. This is
illustrated by the following two code snippets.

Snippet 1:

type t = { foo: t} and u = { foo: u };;

type t = { foo : t; }
and u = { foo : u; }

fun x -> x.foo;;

  • : t -> t =

Snippet 2:

type u = { foo: u } and t = { foo: t };;

type u = { foo : u; }
and t = { foo : t; }

fun x -> x.foo;;

  • : u -> u =

Suggested solution: detect that a record label is being defined twice
in this mutually recursive definition and reject the program. Do the
same for data constructors.

Note: this is not a theoretical example! I have actually written code
like this and got a type error much later in the program.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions