Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004182OCamldocumentationpublic2006-12-07 09:432006-12-18 14:59
Assigned To 
PlatformOSOS Version
Product Version3.09.3 
Target VersionFixed in Version3.10+dev 
Summary0004182: 'exception Exc of (string * string)' and 'exception Exc of string * string' not necessarily the same
DescriptionIf you have in your .mli file this

exception Exc of (string * string)

and in your .ml file this

exception Exc of string * string

then ocamlc will complain that
Exception declarations do not match:
  exception Exc of string * string
is not included in
  exception Exc of (string * string)

Note that this problem doesn't occur for type definitions.

Hardly a major bug, but it is surprising, as typexpr and (typexpr) should be equivalent.
Additional Information$ ocamlc -config
version: 3.09.3
standard_library_default: /opt/godi/lib/ocaml/std-lib
standard_library: /opt/godi/lib/ocaml/std-lib
standard_runtime: /opt/godi/bin/ocamlrun
ccomp_type: cc
bytecomp_c_compiler: gcc -fno-defer-pop -no-cpp-precomp -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT
bytecomp_c_linker: gcc -L/opt/godi/lib
bytecomp_c_libraries: -lcurses -lpthread
native_c_compiler: gcc -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT
native_c_linker: gcc -L/opt/godi/lib
native_partial_linker: ld -r
ranlib: ranlib
cc_profile: -pg
architecture: i386
model: default
system: macosx
ext_obj: .o
ext_asm: .s
ext_lib: .a
ext_dll: .so
os_type: Unix
default_executable_name: a.out
systhread_supported: true
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
Colas (reporter)
2006-12-13 18:08

* has precedence, thus
exception Exc of string * string
(exception Exc of string) * string
whichi is different from
exception Exc of (string * string)
garrigue (manager)
2006-12-14 01:20

exception E of string * string and exception E of (string * string) have different internal representations, so they are incompatible.
This is also true for types!
  module M : sig type t = E of (string * string) end =
    struct type t = E of string * string end;;
Type declarations do not match:
  type t = E of string * string
is not included in
  type t = E of (string * string)
All this is documented in the reference manual.
cookedm (reporter)
2006-12-14 02:05

Responding to Colas:
If `exception Exc of string * string` is equal to `(exception Exc of string) * string`, then `Exc ("a","b")` should be a type error. Which it isn't. `((Exc "a"), "b")` is, though.

Responding to garrigue:
The reference manual, 6.4 Type Expressions -> Parenthesized types, says:

  The type expression ( typexpr ) denotes the same type as typexpr

I thought that was pretty clear :-)

The other problem is that the output produced by ocaml is the same for both
ways. Using types:

# type t1 = E1 of string * string;;
type t1 = E1 of string * string
# type t2 = E2 of (string * string);;
type t2 = E2 of (string * string)
# E1 ("a", "b");;
- : t1 = E1 ("a", "b")
# E2 ("a", "b");;
- : t2 = E2 ("a", "b")

so the pretty-printed version of the two values is identical.

1) E of string * string and E of (string * string) should be identical
2) or, they're different, and should act differently. For instance, E of string * string should be (E of string) * string (which isn't a valid type expression).
oandrieu (reporter)
2006-12-14 09:57

cookedm: there is a difference between a constructor with one tuple argument (declared by "E of (string * string)" and a constructor with multiple arguments "E of string * string".

The revised syntax of camlp4 makes this distinction way more clear by using a different keyword for the multiple arguments case:
  type t = [ E of (string * string) ]
  type t = [ E of string and string ]

But I'm not sure where this is documented in the reference manual. Section 6.8.1, "Type definitions" says: "The constructor declaration constr-name of typexpr declares the name constr-name as a non-constant constructor, whose argument has type typexpr." It doesn't explain anything about constructors with multiple arguments.
doligez (administrator)
2006-12-18 14:59

> Hardly a major bug, but it is surprising, as typexpr and (typexpr) should be equivalent.

In fact, it's a bug in the documentation. typexpr and (typexpr) are indeed equivalent,
but in "Exc of string * string", "string * string" is not parsed as a typexpr, it's two typexprs
separated by a "*" which is part of the syntax of exception declarations. As oandrieu notes,
this is made clear by the revised syntax. On the other hand, the documentation is currently
misleading on this subject.

The documentation will be fixed in 3.10.0.

- Issue History
Date Modified Username Field Change
2006-12-07 09:43 cookedm New Issue
2006-12-13 18:08 Colas Note Added: 0003874
2006-12-14 01:20 garrigue Status new => closed
2006-12-14 01:20 garrigue Note Added: 0003875
2006-12-14 01:20 garrigue Resolution open => no change required
2006-12-14 02:05 cookedm Status closed => feedback
2006-12-14 02:05 cookedm Resolution no change required => reopened
2006-12-14 02:05 cookedm Note Added: 0003876
2006-12-14 09:57 oandrieu Note Added: 0003878
2006-12-18 14:59 doligez Note Added: 0003887
2006-12-18 14:59 doligez Status feedback => closed
2006-12-18 14:59 doligez Resolution reopened => fixed
2006-12-18 14:59 doligez Category OCaml general => OCaml documentation
2006-12-18 14:59 doligez Fixed in Version => 3.10+dev
2017-02-23 16:35 doligez Category OCaml documentation => Documentation
2017-02-23 16:44 doligez Category Documentation => documentation

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker