Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem mixing recursive sum-types and record-types #3605

Closed
vicuna opened this issue Aug 30, 2002 · 1 comment
Closed

Problem mixing recursive sum-types and record-types #3605

vicuna opened this issue Aug 30, 2002 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Aug 30, 2002

Original bug ID: 1359
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Stefan Kral
Version: 3.06
OS: SuSE Linux 7.0 (i386)
Submission from: a49.dialin.tuwien.ac.at (192.35.240.59)

Hi,

I have problems mixing sum-types and records.
Having read nowhere that this is illegal, I
assumed that the following should work...
(also, because references are similarly defined)

First try:


stefan@schlaubi:~/ml > ocaml
Objective Caml version 3.06

type tree =

| Empty 
| Node of complexnode      

and complexnode =
{
mutable pos : int;
s0 : tree;
s1 : tree;
};;
type tree = Empty | Node of complexnode
type complexnode = { mutable pos : int; s0 : tree; s1 : tree; }

{ pos = 1, s0 = Empty, s1 = Empty };;

Characters 11-13:
{ pos = 1, s0 = Empty, s1 = Empty };;
^^
Unbound value s0


At first, I thought that this might be related to the mutable field, pos.
So I tried the same with a record-type containing only immutable fields...


stefan@schlaubi:~/ml > ocaml
Objective Caml version 3.06

type tree =

| Empty 
| Node of complexnode      

and complexnode =
{
pos : int;
s0 : tree;
s1 : tree;
};;
type tree = Empty | Node of complexnode
type complexnode = { pos : int; s0 : tree; s1 : tree; }

{ pos = 1, s0 = Empty, s1 = Empty };;

Characters 11-13:
{ pos = 1, s0 = Empty, s1 = Empty };;
^^
Unbound value s0


Next, I thought that the mutually recursive definition might pose a problem.


stefan@schlaubi:~/ml > ocaml
Objective Caml version 3.06

type tree =

| Empty 
| Node of tree * tree;;

type tree = Empty | Node of tree * tree

type complexnode =

{ 
  mutable pos : int; 
  s0 : tree; 
  s1 : tree;
};;

type complexnode = { mutable pos : int; s0 : tree; s1 : tree; }

{ pos = 1, s0 = Empty, s1 = Empty };;

Characters 11-13:
{ pos = 1, s0 = Empty, s1 = Empty }
^^
Unbound value s0


I tried different names (as a substitute for s0), without success.
First, I thought that the identifier of the second field is always
the culprit.

But then I tried changing the order of fields in the definition
of the record-type...


    Objective Caml version 3.06

type tree =

| Empty 
| Node of tree * tree;;

type tree = Empty | Node of tree * tree

type complexnode =

{ 
  s0 : tree; 
  mutable pos : int; 
  s1 : tree;
};;

type complexnode = { s0 : tree; mutable pos : int; s1 : tree; }

{ s0 = Empty; pos = 1; s1 = Empty };;

  • : complexnode = {s0 = Empty; pos = 1; s1 = Empty}

Alas, it seems so work ;-) I can't help but think that the
other definition(s) should have worked just as well...

Regards,
Stefan

@vicuna
Copy link
Author

vicuna commented Aug 30, 2002

Comment author: administrator

There is no bug, here.


stefan@schlaubi:~/ml > ocaml
Objective Caml version 3.06

type tree =

| Empty 
| Node of complexnode      

and complexnode =
{
mutable pos : int;
s0 : tree;
s1 : tree;
};;
type tree = Empty | Node of complexnode
type complexnode = { mutable pos : int; s0 : tree; s1 : tree; }

{ pos = 1, s0 = Empty, s1 = Empty };;

Characters 11-13:
{ pos = 1, s0 = Empty, s1 = Empty };;
^^
Unbound value s0

You should have written
{ pos = 1; s0 = Empty; s1 = Empty };;

note the ';' instead of your ','. With ',' OCaml try to build
the tuple (1, so=Empty, s1=Empty), not a record.

type complexnode = { s0 : tree; mutable pos : int; s1 : tree; }

{ s0 = Empty; pos = 1; s1 = Empty };;

  • : complexnode = {s0 = Empty; pos = 1; s1 = Empty}

Here you correctly define your record value with ';' instead of ','.

--
Maxence Guesdon

@vicuna vicuna closed this as completed Sep 2, 2002
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant