Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005072OCamlOCaml typingpublic2010-06-14 17:562015-01-06 02:03
Assigned To 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0005072: Absolute name for built-in types such as int, bool, ... ?

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 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'

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"
is nicer than the same message without Pervasives ...

Best regards,

Pierre Letouzey
TagsNo tags attached.
Attached Files

- Relationships
related to 0006655confirmed Alias built-in types and pre-defined exceptions in Pervasives 

-  Notes
garrigue (manager)
2010-06-18 03:12

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.
doligez (administrator)
2011-06-01 23:18

In answer to Jacques: we could just forbid the definition of a module called Builtin.
drup (reporter)
2015-01-05 16:28

Wouldn't [^] solve this issue ?
lpw25 (developer)
2015-01-05 17:25
edited on: 2015-01-05 17:27

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"

- Issue History
Date Modified Username Field Change
2010-06-14 17:56 letouzey New Issue
2010-06-18 03:12 garrigue Note Added: 0005566
2011-06-01 23:18 doligez Note Added: 0005958
2011-06-01 23:18 doligez Status new => acknowledged
2011-06-02 12:46 ygrek Note Added: 0005962
2011-06-02 12:46 ygrek Note Deleted: 0005962
2012-06-01 09:15 garrigue Category OCaml general => OCaml typing
2014-12-22 19:44 doligez Relationship added related to 0006655
2015-01-05 16:28 drup Note Added: 0013008
2015-01-05 17:25 lpw25 Note Added: 0013009
2015-01-05 17:27 lpw25 Note Edited: 0013009 View Revisions

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker