Skip to content

Commit 3cc44fa

Browse files
committed
Removed Union and Recod from Types
1 parent b67b06e commit 3cc44fa

File tree

2 files changed

+87
-75
lines changed

2 files changed

+87
-75
lines changed

src/fable-library/Option.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Union } from "./Types";
21
import { compare, equals, structuralHash } from "./Util";
32

43
// Options are erased in runtime by Fable, but we have
@@ -130,23 +129,35 @@ export function tryOp<T, U>(op: (x: T) => U, arg: T): Option<U> {
130129

131130
// CHOICE
132131

133-
export class Choice<_T1, _T2> extends Union {
134-
public cases() { return ["Choice1Of2", "Choice2Of2"]; }
132+
export class Choice<_T1, _T2> {
133+
public fields: any[];
134+
constructor(public tag: number, ...fields: any[]) { this.fields = fields; }
135+
public cases() { return ["Choice1Of2", "Choice2Of2"]; }
135136
}
136-
export class Choice3<_T1, _T2, _T3> extends Union {
137-
public cases() { return ["Choice1Of3", "Choice2Of3", "Choice3Of3"]; }
137+
export class Choice3<_T1, _T2, _T3> {
138+
public fields: any[];
139+
constructor(public tag: number, ...fields: any[]) { this.fields = fields; }
140+
public cases() { return ["Choice1Of3", "Choice2Of3", "Choice3Of3"]; }
138141
}
139-
export class Choice4<_T1, _T2, _T3, _T4> extends Union {
140-
public cases() { return ["Choice1Of4", "Choice2Of4", "Choice3Of4", "Choice4Of4"]; }
142+
export class Choice4<_T1, _T2, _T3, _T4> {
143+
public fields: any[];
144+
constructor(public tag: number, ...fields: any[]) { this.fields = fields; }
145+
public cases() { return ["Choice1Of4", "Choice2Of4", "Choice3Of4", "Choice4Of4"]; }
141146
}
142-
export class Choice5<_T1, _T2, _T3, _T4, _T5> extends Union {
143-
public cases() { return ["Choice1Of5", "Choice2Of5", "Choice3Of5", "Choice4Of5", "Choice5Of5"]; }
147+
export class Choice5<_T1, _T2, _T3, _T4, _T5> {
148+
public fields: any[];
149+
constructor(public tag: number, ...fields: any[]) { this.fields = fields; }
150+
public cases() { return ["Choice1Of5", "Choice2Of5", "Choice3Of5", "Choice4Of5", "Choice5Of5"]; }
144151
}
145-
export class Choice6<_T1, _T2, _T3, _T4, _T5, _T6> extends Union {
146-
public cases() { return ["Choice1Of6", "Choice2Of6", "Choice3Of6", "Choice4Of6", "Choice5Of6", "Choice6Of6"]; }
152+
export class Choice6<_T1, _T2, _T3, _T4, _T5, _T6> {
153+
public fields: any[];
154+
constructor(public tag: number, ...fields: any[]) { this.fields = fields; }
155+
public cases() { return ["Choice1Of6", "Choice2Of6", "Choice3Of6", "Choice4Of6", "Choice5Of6", "Choice6Of6"]; }
147156
}
148-
export class Choice7<_T1, _T2, _T3, _T4, _T5, _T6, _T7> extends Union {
149-
public cases() { return ["Choice1Of7", "Choice2Of7", "Choice3Of7", "Choice4Of7", "Choice5Of7", "Choice6Of7", "Choice7Of7"]; }
157+
export class Choice7<_T1, _T2, _T3, _T4, _T5, _T6, _T7> {
158+
public fields: any[];
159+
constructor(public tag: number, ...fields: any[]) { this.fields = fields; }
160+
public cases() { return ["Choice1Of7", "Choice2Of7", "Choice3Of7", "Choice4Of7", "Choice5Of7", "Choice6Of7", "Choice7Of7"]; }
150161
}
151162

152163
export function choice1Of2<T1, T2>(x: T1 | T2): Choice<T1, T2> {
@@ -167,8 +178,10 @@ export function tryValueIfChoice2Of2<T1, T2>(x: Choice<T1, T2>): Option<T2> {
167178

168179
// RESULT
169180

170-
export class Result<_T, _U> extends Union {
171-
public cases() { return ["Ok", "Error"]; }
181+
export class Result<_T, _U> {
182+
public fields: any[];
183+
constructor(public tag: number, ...fields: any[]) { this.fields = fields; }
184+
public cases() { return ["Ok", "Error"]; }
172185
}
173186

174187
export function ok<T, U>(x: T | U): Result<T, U> {

src/fable-library/Types.ts

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function unionToJson(self: any) {
112112
}
113113

114114
export function unionGetHashCode(self: any): number {
115-
if (isHashable(self) && !(self instanceof Union)) {
115+
if (isHashable(self)) { // && !(self instanceof Union)) {
116116
return self.GetHashCode();
117117
} else {
118118
const hashes = self.fields.map((x: any) => structuralHash(x));
@@ -124,7 +124,7 @@ export function unionGetHashCode(self: any): number {
124124
export function unionEquals(self: any, other: any) {
125125
if (self === other) {
126126
return true;
127-
} else if (isEquatable(self) && !(self instanceof Union)) {
127+
} else if (isEquatable(self)) { // && !(self instanceof Union)) {
128128
return self.Equals(other);
129129
} else if (!isSameType(self, other)) {
130130
return false;
@@ -138,7 +138,7 @@ export function unionEquals(self: any, other: any) {
138138
export function unionCompareTo(self: any, other: any) {
139139
if (self === other) {
140140
return 0;
141-
} else if (isComparable(self) && !(self instanceof Union)) {
141+
} else if (isComparable(self)) { // && !(self instanceof Union)) {
142142
return self.CompareTo(other);
143143
} else if (!isSameType(self, other)) {
144144
return -1;
@@ -149,43 +149,43 @@ export function unionCompareTo(self: any, other: any) {
149149
}
150150
}
151151

152-
export class Union implements IEquatable<any>, IComparable<any> {
153-
public tag: number;
154-
public fields: any[];
152+
// export class Union implements IEquatable<any>, IComparable<any> {
153+
// public tag: number;
154+
// public fields: any[];
155155

156-
public cases(): string[] {
157-
return [];
158-
}
156+
// public cases(): string[] {
157+
// return [];
158+
// }
159159

160-
constructor(tag: number, ...fields: any[]) {
161-
this.tag = tag | 0;
162-
this.fields = fields;
163-
}
160+
// constructor(tag: number, ...fields: any[]) {
161+
// this.tag = tag | 0;
162+
// this.fields = fields;
163+
// }
164164

165-
public toJSON() {
166-
return unionToJson(this);
167-
}
165+
// public toJSON() {
166+
// return unionToJson(this);
167+
// }
168168

169-
public toString() {
170-
return this.ToString();
171-
}
169+
// public toString() {
170+
// return this.ToString();
171+
// }
172172

173-
public ToString() {
174-
return unionToString(this);
175-
}
173+
// public ToString() {
174+
// return unionToString(this);
175+
// }
176176

177-
public GetHashCode() {
178-
return unionGetHashCode(this);
179-
}
177+
// public GetHashCode() {
178+
// return unionGetHashCode(this);
179+
// }
180180

181-
public Equals(other: any) {
182-
return unionEquals(this, other);
183-
}
181+
// public Equals(other: any) {
182+
// return unionEquals(this, other);
183+
// }
184184

185-
public CompareTo(other: any) {
186-
return unionCompareTo(this, other);
187-
}
188-
}
185+
// public CompareTo(other: any) {
186+
// return unionCompareTo(this, other);
187+
// }
188+
// }
189189

190190
export function recordToString(self: any) {
191191
if (isStringable(self)) {
@@ -205,7 +205,7 @@ export function recordToJson(self: any, getFieldNames?: (arg: any) => any) {
205205
}
206206

207207
export function recordGetHashCode(self: any) {
208-
if (isHashable(self) && !(self instanceof Record)) {
208+
if (isHashable(self)) { // && !(self instanceof Record)) {
209209
return self.GetHashCode();
210210
} else {
211211
const hashes = Object.values(self).map((v) => structuralHash(v));
@@ -216,7 +216,7 @@ export function recordGetHashCode(self: any) {
216216
export function recordEquals(self: any, other: any) {
217217
if (self === other) {
218218
return true;
219-
} else if (isEquatable(self) && !(self instanceof Record)) {
219+
} else if (isEquatable(self)) { // && !(self instanceof Record)) {
220220
return self.Equals(other);
221221
} else if (!isSameType(self, other)) {
222222
return false;
@@ -234,7 +234,7 @@ export function recordEquals(self: any, other: any) {
234234
export function recordCompareTo(self: any, other: any) {
235235
if (self === other) {
236236
return 0;
237-
} else if (isComparable(self) && !(self instanceof Record)) {
237+
} else if (isComparable(self)) { // && !(self instanceof Record)) {
238238
return self.CompareTo(other);
239239
} else if (!isSameType(self, other)) {
240240
return -1;
@@ -250,42 +250,41 @@ export function recordCompareTo(self: any, other: any) {
250250
}
251251
}
252252

253-
export class Record implements IEquatable<any>, IComparable<any> {
253+
// export class Record implements IEquatable<any>, IComparable<any> {
254254

255-
public toJSON() {
256-
return recordToJson(this);
257-
}
255+
// public toJSON() {
256+
// return recordToJson(this);
257+
// }
258258

259-
public toString() {
260-
return this.ToString();
261-
}
259+
// public toString() {
260+
// return this.ToString();
261+
// }
262262

263-
public ToString() {
264-
return recordToString(this);
265-
}
263+
// public ToString() {
264+
// return recordToString(this);
265+
// }
266266

267-
public GetHashCode() {
268-
return recordGetHashCode(this);
269-
}
267+
// public GetHashCode() {
268+
// return recordGetHashCode(this);
269+
// }
270270

271-
public Equals(other: any) {
272-
return recordEquals(this, other);
273-
}
271+
// public Equals(other: any) {
272+
// return recordEquals(this, other);
273+
// }
274274

275-
public CompareTo(other: any) {
276-
return recordCompareTo(this, other);
277-
}
278-
}
275+
// public CompareTo(other: any) {
276+
// return recordCompareTo(this, other);
277+
// }
278+
// }
279279

280280
export function anonRecord(o: any) {
281-
return Object.assign(Object.create(Record.prototype), o);
281+
// return Object.assign(Object.create(Record.prototype), o);
282+
return o;
282283
}
283284

284-
export class FSharpRef<T> extends Record {
285+
export class FSharpRef<T> {
285286
public contents: T;
286-
287287
constructor(contents: T | null) {
288-
super();
289288
this.contents = contents as T;
290289
}
291290
}
@@ -392,5 +391,5 @@ export class MatchFailureException extends FSharpException {
392391
}
393392
}
394393

395-
export class Attribute extends SystemObject {
394+
export class Attribute {
396395
}

0 commit comments

Comments
 (0)