Hacks‎ > ‎

Other small OCaml patches

Path name simplification

Target : OCaml 3.11.1
Status: 1.0
Download: here

This patch is to simplify OCaml compiler path name printing. The paths which are open in the context are no longer printed. It also tries alias type expansion for data type names to have shorter names at printing:

The original:

# open Hashtbl;;
# let tbl = Hashtbl.create 10;;
val tbl : ('_a, '_b) Hashtbl.t = <abstr>
# tbl + 1;;
Characters 0-3:
  tbl + 1;;
  ^^^
Error: This expression has type ('a, 'b) Hashtbl.t
       but an expression was expected of type int

With this patch:

# open Hashtbl;;
# let tbl = Hashtbl.create 10;;
val tbl : ('_a, '_b) t = <abstr>
# tbl + 1;;
Characters 0-3:
  tbl + 1;;
  ^^^
Error: This expression has type ('a, 'b) t
       but an expression was expected of type int

The original:
# type t = int;;
type t = int
# type long_name = int;;
type long_name = int
# (1 : t);;
- : t = 1
# (1 : long_name);;
- : long_name = 1

With this patch:
# type t = int;;
type t = int
# type long_name = int;;
type long_name = int
# (1 : t);;
- : t = 1    (* t is shorter than int. *)
# (1 : long_name);;
- : int = 1    (* int is shorter than long_name. It is also equal to t which is even shorter, but the type system does not know it. *)

Simplification rules

  1. Opened module paths are omitted like M.N.O.P.t ==> O.P.t when:
    •  M.N is opened but not M.N.O or M.N.O.P
    • O.P.t can be parsed back to M.N.O.P.t without ambiguity.
  2. A constructor data type (variants and records) name may be expanded to one of its aliases, if the alias is a constructor type and its name is heuristically shorter than the former.
Č
ċ
ď
path-name-simplification-patch-1.0.txt
(86k)
Jun Furuse,
Dec 2, 2009, 12:05 AM
Comments

Recent site activity

Contact