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

Absolute name for built-in types such as int, bool, ... ? #5072

Closed
vicuna opened this issue Jun 14, 2010 · 5 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Jun 14, 2010

Original bug ID: 5072
Reporter: letouzey
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2016-12-08T10:55:04Z)
Resolution: duplicate
Priority: normal
Severity: feature
Category: typing
Duplicate of: #6655
Monitored by: @whitequark dsheets @ygrek @Chris00

Bug description

Hi

As said in the documentation of the core library:
[
The following built-in types and predefined exceptions are always defined in
the compilation environment, but are not part of any module. As a consequence,
they can only be referred by their short names
]

Well, there are rare situations where it would be handy to have
absolute names for int, bool, char, etc, but indeed Pervasives.int isn't
working. Truly, any user can create its own long name for int thanks to
something like

module MyPervasives = struct
type int' = int
type int = int'
end

But it would be nice to have something like that by default.

(By the way, as illustrated above, it's really painful to have only
a type declaration syntax which is recursive, even for type abbreviation).

Maybe this disambiguation need is really specific to my own parish, which is
ocaml code generation from a system where users may have their own naming
conventions and expect nonetheless the obtained code to interact nicely with
ocaml's stdlib. But placing int and others inside Pervasives would probably
also allow to have nicer error message when a beginnner redefines int by
mistake: "foo has type int but is expected to have type Pervasives.int"
is nicer than the same message without Pervasives ...

Best regards,

Pierre Letouzey

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 18, 2010

Comment author: @garrigue

This is a actually a problem for the ocaml compiler developers too...

The reason these types are not in Pervarsives is that they are used internally by the compiler, and they need to be defined before reading Pervasives.
An alternative solution would be to put them in another module, named Builtin for instance, but then we still have the risk of somebody defining a module with the same name.

If somebody has a good solution for this problem, I am interested.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 1, 2011

Comment author: @damiendoligez

In answer to Jacques: we could just forbid the definition of a module called Builtin.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jan 5, 2015

Comment author: @Drup

Wouldn't #5849 solve this issue ?

@vicuna

This comment has been minimized.

Copy link
Author

commented Jan 5, 2015

Comment author: @lpw25

We could just give them a longer name in the compiler (e.g. builtin_int) and then rebind the name with an alias in Pervasives:

type int = builtin_int

We could also take this further by allowing a syntax for "external" types analoguous to how externel definitions are used to bind compiler primitives. For example:

type int = "%int"
@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 8, 2016

Comment author: @alainfrisch

Duplicate of 6655.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.