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

Exception aliasing not available in signatures #5625

Closed
vicuna opened this issue May 29, 2012 · 3 comments
Closed

Exception aliasing not available in signatures #5625

vicuna opened this issue May 29, 2012 · 3 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented May 29, 2012

Original bug ID: 5625
Reporter: thelema
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2015-12-11T18:04:48Z)
Resolution: not a bug
Priority: normal
Severity: feature
Version: 3.12.1
Category: ~DO NOT USE (was: OCaml general)

Bug description

An exception can be defined as equal to another exception:
exception-definition ::= exception constr-name = constr
But within a .mli file, one cannot expose this equality:
specification ::= exception constr-decl

Steps to reproduce

add:

exception Empty = Stack.Empty

to a .mli file

Additional information

Batteries has use for "exception Empty = Stack.Empty" in our batStack.mli file, otherwise we'll have a BatStack.Empty and a Stack.Empty that aren't the same. We could remove the exception from the .mli file, but then it wouldn't be in the documentation as it should, and the test that (BatStack : module type of Stack) would fail, and would need... hmm, I don't think that the exception can be removed from the module type. But that's another issue.

@vicuna
Copy link
Author

vicuna commented May 29, 2012

Comment author: @garrigue

There is a confusion here.
An exception constructor is just a value, that you can re-export at the value level using the "exception E = " construct.
There is no need to show the sharing in the interface: they are identical at the value level.

@vicuna
Copy link
Author

vicuna commented May 29, 2012

Comment author: thelema

Ah, my mistake. I was testing using (==), but this is apparently a bad function to use on exceptions.

module A = struct exception X end;;

module A : sig exception X end

module B : sig exception X end = struct exception X = A.X end;;

module B : sig exception X end

B.X = A.X;;

  • : bool = true

B.X == A.X;;

  • : bool = false

A.X == A.X;;

  • : bool = false

Thanks for the quick clarification.

@vicuna
Copy link
Author

vicuna commented Jun 1, 2012

Comment author: @alainfrisch

A new exception value is created each time you refer to the exception constructor, so you get physically different values (and == returns false).

"=" is also not very good on exceptions, as it compares only the name of the constructors (as strings) and, if they match, the arguments (even if they have different types).

If you can, you should prefer pattern matching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants