Skip to content

Commit f4006cb

Browse files
Julowjonludlam
authored andcommitted
Remove hand-written compare functions
Stdlib.compare can be used on these types.
1 parent 4bd19ad commit f4006cb

File tree

2 files changed

+4
-92
lines changed

2 files changed

+4
-92
lines changed

src/model/names.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,7 @@ module Name : Name = struct
6868

6969
let equal (x : t) (y : t) = x = y
7070

71-
let compare x y =
72-
match (x, y) with
73-
| Internal (x, _), Internal (y, _) -> String.compare x y
74-
| Std x, Std y -> String.compare x y
75-
| Internal _, Std _ -> -1
76-
| Std _, Internal _ -> 1
71+
let compare = compare
7772

7873
let fmt ppf x = Format.fprintf ppf "%s" (to_string x)
7974

src/model/paths.ml

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -72,95 +72,12 @@ module Identifier = struct
7272

7373
let label_parent n = label_parent_aux (n :> t)
7474

75-
let constructor_id : t -> int = function
76-
| `Root _ -> 1
77-
| `RootPage _ -> 2
78-
| `Module _ -> 3
79-
| `Parameter _ -> 4
80-
| `Result _ -> 5
81-
| `ModuleType _ -> 6
82-
| `Type _ -> 7
83-
| `CoreType _ -> 8
84-
| `Constructor _ -> 9
85-
| `Field _ -> 10
86-
| `Extension _ -> 11
87-
| `Exception _ -> 12
88-
| `CoreException _ -> 13
89-
| `Value _ -> 14
90-
| `Class _ -> 15
91-
| `ClassType _ -> 16
92-
| `Method _ -> 17
93-
| `InstanceVariable _ -> 18
94-
| `Label _ -> 19
95-
| `Page _ -> 20
96-
| `LeafPage _ -> 21
97-
98-
let std_compare = compare
99-
100-
let rec compare : t -> t -> int =
101-
fun x y ->
102-
match (x, y) with
103-
| `Root (r, s), `Root (r', s') ->
104-
let s = ModuleName.compare s s' in
105-
if s <> 0 then s else compare (r :> t) (r' :> t)
106-
| `RootPage s, `RootPage s' -> PageName.compare s s'
107-
| `Page (r, s), `Page (r', s') ->
108-
let s = PageName.compare s s' in
109-
if s <> 0 then s else compare (r :> t) (r' :> t)
110-
| `LeafPage (r, s), `LeafPage (r', s') ->
111-
let s = PageName.compare s s' in
112-
if s <> 0 then s else compare (r :> t) (r' :> t)
113-
| `Module (p, s), `Module (p', s') ->
114-
let s = ModuleName.compare s s' in
115-
if s <> 0 then s else compare (p :> t) (p' :> t)
116-
| `Parameter (p, s), `Parameter (p', s') ->
117-
let s = ParameterName.compare s s' in
118-
if s <> 0 then s else compare (p :> t) (p' :> t)
119-
| `Result p, `Result p' -> compare (p :> t) (p' :> t)
120-
| `ModuleType (p, s), `ModuleType (p', s') ->
121-
let s = ModuleTypeName.compare s s' in
122-
if s <> 0 then s else compare (p :> t) (p' :> t)
123-
| `Type (p, s), `Type (p', s') ->
124-
let s = TypeName.compare s s' in
125-
if s <> 0 then s else compare (p :> t) (p' :> t)
126-
| `CoreType s, `CoreType s' -> TypeName.compare s s'
127-
| `Constructor (p, s), `Constructor (p', s') ->
128-
let s = ConstructorName.compare s s' in
129-
if s <> 0 then s else compare (p :> t) (p' :> t)
130-
| `Field (p, s), `Field (p', s') ->
131-
let s = FieldName.compare s s' in
132-
if s <> 0 then s else compare (p :> t) (p' :> t)
133-
| `Extension (p, s), `Extension (p', s') ->
134-
let s = ExtensionName.compare s s' in
135-
if s <> 0 then s else compare (p :> t) (p' :> t)
136-
| `Exception (p, s), `Exception (p', s') ->
137-
let s = ExceptionName.compare s s' in
138-
if s <> 0 then s else compare (p :> t) (p' :> t)
139-
| `CoreException s, `CoreException s' -> ExceptionName.compare s s'
140-
| `Value (p, s), `Value (p', s') ->
141-
let s = ValueName.compare s s' in
142-
if s <> 0 then s else compare (p :> t) (p' :> t)
143-
| `Class (p, s), `Class (p', s') ->
144-
let s = ClassName.compare s s' in
145-
if s <> 0 then s else compare (p :> t) (p' :> t)
146-
| `ClassType (p, s), `ClassType (p', s') ->
147-
let s = ClassTypeName.compare s s' in
148-
if s <> 0 then s else compare (p :> t) (p' :> t)
149-
| `Method (p, s), `Method (p', s') ->
150-
let s = MethodName.compare s s' in
151-
if s <> 0 then s else compare (p :> t) (p' :> t)
152-
| `InstanceVariable (p, s), `InstanceVariable (p', s') ->
153-
let s = InstanceVariableName.compare s s' in
154-
if s <> 0 then s else compare (p :> t) (p' :> t)
155-
| `Label (p, s), `Label (p', s') ->
156-
let s = LabelName.compare s s' in
157-
if s <> 0 then s else compare (p :> t) (p' :> t)
158-
| x, y -> std_compare (constructor_id x) (constructor_id y)
159-
160-
let equal : t -> t -> bool = fun x y -> compare x y = 0
75+
let equal = ( = )
16176

16277
let hash = Hashtbl.hash
16378

79+
let compare = compare
80+
16481
type any = t
16582

16683
module Signature = struct

0 commit comments

Comments
 (0)