rename all TS classes

This commit is contained in:
Vyacheslav Matyukhin 2022-08-28 20:19:44 +04:00
parent feeb9e85f1
commit b50061a91a
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
17 changed files with 296 additions and 390 deletions

View File

@ -1,5 +1,5 @@
import { Project, SquiggleValue } from "../../src/js"; import { SqProject, SqValue } from "../../src/js";
import { NumberValue } from "../../src/js/SquiggleValue"; import { SqNumberValue } from "../../src/js/SqValue";
import { failDefault, testRun } from "./TestHelpers"; import { failDefault, testRun } from "./TestHelpers";
function Ok<b>(x: b) { function Ok<b>(x: b) {
@ -12,7 +12,7 @@ describe("Simple calculations and results", () => {
expect(result.tag).toEqual("Number"); expect(result.tag).toEqual("Number");
switch (result.tag) { switch (result.tag) {
case "Number": case "Number":
expect(result.value()).toEqual(5); expect(result.value).toEqual(5);
break; break;
default: default:
fail(); fail();
@ -22,11 +22,11 @@ describe("Simple calculations and results", () => {
// }); // });
}); });
test("10+10", () => { test("10+10", () => {
let result = testRun("10 + 10") as NumberValue; let result = testRun("10 + 10") as SqNumberValue;
expect(result.tag).toEqual("Number"); expect(result.tag).toEqual("Number");
switch (result.tag) { switch (result.tag) {
case "Number": case "Number":
expect(result.value()).toEqual(20); expect(result.value).toEqual(20);
break; break;
default: default:
fail(); fail();

View File

@ -1,4 +1,4 @@
import { run, SquiggleValue } from "../../src/js/index"; import { run, SqValue } from "../../src/js";
export function testRun(x: string) { export function testRun(x: string) {
const { result, bindings } = run(x); // FIXME - set environment const { result, bindings } = run(x); // FIXME - set environment

View File

@ -1,9 +1,9 @@
import * as RSArray from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Array.gen"; import * as RSArray from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Array.gen";
import { AbstractSquiggleValue, wrapSquiggleValue } from "./SquiggleValue"; import { wrapValue } from "./SqValue";
type T = RSArray.squiggleValue_Array; type T = RSArray.squiggleValue_Array;
export class SquiggleArray { export class SqArray {
_value: T; _value: T;
constructor(_value: T) { constructor(_value: T) {
@ -11,6 +11,6 @@ export class SquiggleArray {
} }
getValues() { getValues() {
return RSArray.getValues(this._value).map(wrapSquiggleValue); return RSArray.getValues(this._value).map(wrapValue);
} }
} }

View File

@ -1,20 +1,20 @@
import * as RSDistribution from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution.gen"; import * as RSDistribution from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution.gen";
import { distributionTag as Tag } from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_tag"; import { distributionTag as Tag } from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_tag";
import { environment } from "../rescript/ForTS/ForTS__Types.gen"; import { environment } from "../rescript/ForTS/ForTS__Types.gen";
import { DistributionError } from "./DistributionError"; import { SqDistributionError } from "./SqDistributionError";
import { wrapPointSetDist } from "./PointSetDist"; import { wrapPointSetDist } from "./SqPointSetDist";
import { resultMap2 } from "./types"; import { resultMap2 } from "./types";
type T = RSDistribution.distribution; type T = RSDistribution.distribution;
export { Tag }; export { Tag as SqDistributionTag };
export const wrapDistribution = (value: T): Distribution => { export const wrapDistribution = (value: T): SqDistribution => {
const tag = RSDistribution.getTag(value); const tag = RSDistribution.getTag(value);
return new tagToClass[tag](value); return new tagToClass[tag](value);
}; };
abstract class AbstractDistribution { abstract class SqAbstractDistribution {
abstract tag: Tag; abstract tag: Tag;
_value: T; _value: T;
@ -27,7 +27,7 @@ abstract class AbstractDistribution {
return resultMap2( return resultMap2(
innerResult, innerResult,
wrapPointSetDist, wrapPointSetDist,
(v: RSDistribution.distributionError) => new DistributionError(v) (v: RSDistribution.distributionError) => new SqDistributionError(v)
); );
} }
@ -39,7 +39,7 @@ abstract class AbstractDistribution {
return resultMap2( return resultMap2(
RSDistribution.mean({ env }, this._value), RSDistribution.mean({ env }, this._value),
(v: number) => v, (v: number) => v,
(e: RSDistribution.distributionError) => new DistributionError(e) (e: RSDistribution.distributionError) => new SqDistributionError(e)
); );
} }
@ -47,7 +47,7 @@ abstract class AbstractDistribution {
return resultMap2( return resultMap2(
RSDistribution.inv({ env }, this._value, n), RSDistribution.inv({ env }, this._value, n),
(v: number) => v, (v: number) => v,
(e: RSDistribution.distributionError) => new DistributionError(e) (e: RSDistribution.distributionError) => new SqDistributionError(e)
); );
} }
@ -55,13 +55,13 @@ abstract class AbstractDistribution {
return resultMap2( return resultMap2(
RSDistribution.stdev({ env }, this._value), RSDistribution.stdev({ env }, this._value),
(v: number) => v, (v: number) => v,
(e: RSDistribution.distributionError) => new DistributionError(e) (e: RSDistribution.distributionError) => new SqDistributionError(e)
); );
} }
} }
const valueMethod = <IR>( const valueMethod = <IR>(
_this: AbstractDistribution, _this: SqAbstractDistribution,
rsMethod: (v: T) => IR | null | undefined rsMethod: (v: T) => IR | null | undefined
) => { ) => {
const value = rsMethod(_this._value); const value = rsMethod(_this._value);
@ -69,7 +69,7 @@ const valueMethod = <IR>(
return value; return value;
}; };
export class PointSetDistribution extends AbstractDistribution { export class SqPointSetDistribution extends SqAbstractDistribution {
tag = Tag.DtPointSet; tag = Tag.DtPointSet;
value() { value() {
@ -77,7 +77,7 @@ export class PointSetDistribution extends AbstractDistribution {
} }
} }
export class SampleSetDistribution extends AbstractDistribution { export class SqSampleSetDistribution extends SqAbstractDistribution {
tag = Tag.DtSampleSet; tag = Tag.DtSampleSet;
value() { value() {
@ -85,7 +85,7 @@ export class SampleSetDistribution extends AbstractDistribution {
} }
} }
export class SymbolicDistribution extends AbstractDistribution { export class SqSymbolicDistribution extends SqAbstractDistribution {
tag = Tag.DtSymbolic; tag = Tag.DtSymbolic;
value() { value() {
@ -94,12 +94,12 @@ export class SymbolicDistribution extends AbstractDistribution {
} }
const tagToClass = { const tagToClass = {
[Tag.DtPointSet]: PointSetDistribution, [Tag.DtPointSet]: SqPointSetDistribution,
[Tag.DtSampleSet]: SampleSetDistribution, [Tag.DtSampleSet]: SqSampleSetDistribution,
[Tag.DtSymbolic]: SymbolicDistribution, [Tag.DtSymbolic]: SqSymbolicDistribution,
} as const; } as const;
export type Distribution = export type SqDistribution =
| PointSetDistribution | SqPointSetDistribution
| SampleSetDistribution | SqSampleSetDistribution
| SymbolicDistribution; | SqSymbolicDistribution;

View File

@ -2,7 +2,7 @@ import * as RSDistributionError from "../rescript/ForTS/ForTS_Distribution/ForTS
type T = RSDistributionError.distributionError; type T = RSDistributionError.distributionError;
export class DistributionError { export class SqDistributionError {
_value: T; _value: T;
constructor(_value: T) { constructor(_value: T) {

View File

@ -1,6 +1,6 @@
import * as RSErrorValue from "../rescript/ForTS/ForTS_Reducer_ErrorValue.gen"; import * as RSErrorValue from "../rescript/ForTS/ForTS_Reducer_ErrorValue.gen";
export class ErrorValue { export class SqError {
_value: RSErrorValue.reducerErrorValue; _value: RSErrorValue.reducerErrorValue;
constructor(_value: RSErrorValue.reducerErrorValue) { constructor(_value: RSErrorValue.reducerErrorValue) {

View File

@ -2,7 +2,7 @@ import * as RSLambda from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleV
type T = RSLambda.squiggleValue_Lambda; type T = RSLambda.squiggleValue_Lambda;
export class Lambda { export class SqLambda {
_value: T; _value: T;
constructor(_value: T) { constructor(_value: T) {

View File

@ -2,7 +2,7 @@ import * as RSDeclaration from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_Squi
type T = RSDeclaration.squiggleValue_Declaration; type T = RSDeclaration.squiggleValue_Declaration;
export class LambdaDeclaration { export class SqLambdaDeclaration {
_value: T; _value: T;
constructor(_value: T) { constructor(_value: T) {

View File

@ -1,6 +1,6 @@
import * as RSModuleValue from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.gen"; import * as RSModuleValue from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.gen";
export class NameSpace { export class SqModule {
_value: RSModuleValue.squiggleValue_Module; _value: RSModuleValue.squiggleValue_Module;
constructor(_value: RSModuleValue.squiggleValue_Module) { constructor(_value: RSModuleValue.squiggleValue_Module) {

View File

@ -4,15 +4,15 @@ import { pointSetDistributionTag as Tag } from "../rescript/ForTS/ForTS_Distribu
type T = RSPointSetDist.pointSetDistribution; type T = RSPointSetDist.pointSetDistribution;
export type point = { x: number; y: number }; export type SqPoint = { x: number; y: number };
export type shape = { export type SqShape = {
continuous: point[]; continuous: SqPoint[];
discrete: point[]; discrete: SqPoint[];
}; };
const shapePoints = ( const shapePoints = (
x: RSPointSetDist.continuousShape | RSPointSetDist.discreteShape x: RSPointSetDist.continuousShape | RSPointSetDist.discreteShape
): point[] => { ): SqPoint[] => {
let xs = x.xyShape.xs; let xs = x.xyShape.xs;
let ys = x.xyShape.ys; let ys = x.xyShape.ys;
return _.zipWith(xs, ys, (x, y) => ({ x, y })); return _.zipWith(xs, ys, (x, y) => ({ x, y }));
@ -24,18 +24,18 @@ export const wrapPointSetDist = (value: T) => {
return new tagToClass[tag](value); return new tagToClass[tag](value);
}; };
abstract class AbstractPointSetDist { abstract class SqAbstractPointSetDist {
_value: T; _value: T;
constructor(_value: T) { constructor(_value: T) {
this._value = _value; this._value = _value;
} }
abstract asShape(): shape; abstract asShape(): SqShape;
} }
const valueMethod = <IR>( const valueMethod = <IR>(
_this: AbstractPointSetDist, _this: SqAbstractPointSetDist,
rsMethod: (v: T) => IR | null | undefined rsMethod: (v: T) => IR | null | undefined
) => { ) => {
const value = rsMethod(_this._value); const value = rsMethod(_this._value);
@ -43,7 +43,7 @@ const valueMethod = <IR>(
return value; return value;
}; };
export class MixedPointSetDist extends AbstractPointSetDist { export class SqMixedPointSetDist extends SqAbstractPointSetDist {
tag = Tag.PstMixed as const; tag = Tag.PstMixed as const;
get value(): RSPointSetDist.mixedShape { get value(): RSPointSetDist.mixedShape {
@ -59,7 +59,7 @@ export class MixedPointSetDist extends AbstractPointSetDist {
} }
} }
export class DiscretePointSetDist extends AbstractPointSetDist { export class SqDiscretePointSetDist extends SqAbstractPointSetDist {
tag = Tag.PstDiscrete as const; tag = Tag.PstDiscrete as const;
get value(): RSPointSetDist.discreteShape { get value(): RSPointSetDist.discreteShape {
@ -75,7 +75,7 @@ export class DiscretePointSetDist extends AbstractPointSetDist {
} }
} }
export class ContinuousPointSetDist extends AbstractPointSetDist { export class SqContinuousPointSetDist extends SqAbstractPointSetDist {
tag = Tag.PstContinuous as const; tag = Tag.PstContinuous as const;
get value(): RSPointSetDist.continuousShape { get value(): RSPointSetDist.continuousShape {
@ -92,12 +92,12 @@ export class ContinuousPointSetDist extends AbstractPointSetDist {
} }
const tagToClass = { const tagToClass = {
[Tag.PstMixed]: MixedPointSetDist, [Tag.PstMixed]: SqMixedPointSetDist,
[Tag.PstDiscrete]: DiscretePointSetDist, [Tag.PstDiscrete]: SqDiscretePointSetDist,
[Tag.PstContinuous]: ContinuousPointSetDist, [Tag.PstContinuous]: SqContinuousPointSetDist,
} as const; } as const;
export type PointSetDist = export type SqPointSetDist =
| MixedPointSetDist | SqMixedPointSetDist
| DiscretePointSetDist | SqDiscretePointSetDist
| ContinuousPointSetDist; | SqContinuousPointSetDist;

View File

@ -1,12 +1,12 @@
import * as RSProject from "../rescript/ForTS/ForTS_ReducerProject.gen"; import * as RSProject from "../rescript/ForTS/ForTS_ReducerProject.gen";
import { reducerErrorValue } from "../rescript/ForTS/ForTS_Reducer_ErrorValue.gen"; import { reducerErrorValue } from "../rescript/ForTS/ForTS_Reducer_ErrorValue.gen";
import { environment } from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_Environment.gen"; import { environment } from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_Environment.gen";
import { ErrorValue } from "./ErrorValue"; import { SqError } from "./SqError";
import { NameSpace as NameSpace } from "./NameSpace"; import { SqModule } from "./SqModule";
import { wrapSquiggleValue } from "./SquiggleValue"; import { wrapValue } from "./SqValue";
import { resultMap2 } from "./types"; import { resultMap2 } from "./types";
export class Project { export class SqProject {
_value: RSProject.reducerProject; _value: RSProject.reducerProject;
constructor(_value: RSProject.reducerProject) { constructor(_value: RSProject.reducerProject) {
@ -14,7 +14,7 @@ export class Project {
} }
static create() { static create() {
return new Project(RSProject.createProject()); return new SqProject(RSProject.createProject());
} }
getSourceIds() { getSourceIds() {
@ -53,7 +53,7 @@ export class Project {
return resultMap2( return resultMap2(
RSProject.getIncludes(this._value, sourceId), RSProject.getIncludes(this._value, sourceId),
(a) => a, (a) => a,
(v: reducerErrorValue) => new ErrorValue(v) (v: reducerErrorValue) => new SqError(v)
); );
} }
@ -94,15 +94,15 @@ export class Project {
} }
getBindings(sourceId: string) { getBindings(sourceId: string) {
return new NameSpace(RSProject.getBindings(this._value, sourceId)); return new SqModule(RSProject.getBindings(this._value, sourceId));
} }
getResult(sourceId: string) { getResult(sourceId: string) {
const innerResult = RSProject.getResult(this._value, sourceId); const innerResult = RSProject.getResult(this._value, sourceId);
return resultMap2( return resultMap2(
innerResult, innerResult,
wrapSquiggleValue, wrapValue,
(v: reducerErrorValue) => new ErrorValue(v) (v: reducerErrorValue) => new SqError(v)
); );
} }

View File

@ -1,9 +1,9 @@
import * as RSRecord from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Record.gen"; import * as RSRecord from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Record.gen";
import { AbstractSquiggleValue, wrapSquiggleValue } from "./SquiggleValue"; import { wrapValue } from "./SqValue";
type T = RSRecord.squiggleValue_Record; type T = RSRecord.squiggleValue_Record;
export class Record { export class SqRecord {
_value: T; _value: T;
constructor(_value: T) { constructor(_value: T) {
@ -12,7 +12,7 @@ export class Record {
entries() { entries() {
return RSRecord.getKeyValuePairs(this._value).map( return RSRecord.getKeyValuePairs(this._value).map(
([k, v]) => [k, wrapSquiggleValue(v)] as const ([k, v]) => [k, wrapValue(v)] as const
); );
} }
} }

View File

@ -2,7 +2,7 @@ import * as RSType from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleVal
type T = RSType.squiggleValue_Type; type T = RSType.squiggleValue_Type;
export class Type { export class SqType {
_value: T; _value: T;
constructor(_value: T) { constructor(_value: T) {

View File

@ -0,0 +1,210 @@
import * as RSValue from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue.gen";
import { squiggleValueTag as Tag } from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_tag";
import { wrapDistribution } from "./SqDistribution";
import { SqLambda } from "./SqLambda";
import { SqLambdaDeclaration } from "./SqLambdaDeclaration";
import { SqModule } from "./SqModule";
import { SqRecord } from "./SqRecord";
import { SqArray } from "./SqArray";
import { SqType } from "./SqType";
export { Tag as SqValueTag };
type T = RSValue.squiggleValue;
export const wrapValue = (value: T): SqValue => {
const tag = RSValue.getTag(value);
return new tagToClass[tag](value);
};
export abstract class SqAbstractValue {
abstract tag: Tag;
_value: T;
constructor(value: T) {
this._value = value;
}
}
const valueMethod = <IR>(
_this: SqAbstractValue,
rsMethod: (v: T) => IR | null | undefined
) => {
const value = rsMethod(_this._value);
if (!value) throw new Error("Internal casting error");
return value;
};
export class SqArrayValue extends SqAbstractValue {
tag = Tag.SvtArray as const;
get value() {
return new SqArray(valueMethod(this, RSValue.getArray));
}
}
export class SqArrayStringValue extends SqAbstractValue {
tag = Tag.SvtArrayString as const;
get value() {
return valueMethod(this, RSValue.getArrayString);
}
}
export class SqBoolValue extends SqAbstractValue {
tag = Tag.SvtBool as const;
get value() {
return valueMethod(this, RSValue.getBool);
}
}
export class SqCallValue extends SqAbstractValue {
tag = Tag.SvtCall as const;
get value() {
return valueMethod(this, RSValue.getCall);
}
}
export class SqDateValue extends SqAbstractValue {
tag = Tag.SvtDate as const;
get value() {
return valueMethod(this, RSValue.getDate);
}
}
export class SqDeclarationValue extends SqAbstractValue {
tag = Tag.SvtDeclaration as const;
get value() {
return new SqLambdaDeclaration(valueMethod(this, RSValue.getDeclaration));
}
}
export class SqDistributionValue extends SqAbstractValue {
tag = Tag.SvtDistribution as const;
get value() {
return wrapDistribution(valueMethod(this, RSValue.getDistribution));
}
}
export class SqLambdaValue extends SqAbstractValue {
tag = Tag.SvtLambda as const;
get value() {
return new SqLambda(valueMethod(this, RSValue.getLambda));
}
}
export class SqModuleValue extends SqAbstractValue {
tag = Tag.SvtModule as const;
get value() {
return new SqModule(valueMethod(this, RSValue.getModule));
}
}
export class SqNumberValue extends SqAbstractValue {
tag = Tag.SvtNumber as const;
get value() {
return valueMethod(this, RSValue.getNumber);
}
}
export class SqRecordValue extends SqAbstractValue {
tag = Tag.SvtRecord as const;
get value() {
return new SqRecord(valueMethod(this, RSValue.getRecord));
}
}
export class SqStringValue extends SqAbstractValue {
tag = Tag.SvtString as const;
get value(): string {
return valueMethod(this, RSValue.getString);
}
}
export class SqSymbolValue extends SqAbstractValue {
tag = Tag.SvtSymbol as const;
get value(): string {
return valueMethod(this, RSValue.getSymbol);
}
}
export class SqTimeDurationValue extends SqAbstractValue {
tag = Tag.SvtTimeDuration as const;
get value() {
return valueMethod(this, RSValue.getTimeDuration);
}
}
export class SqTypeValue extends SqAbstractValue {
tag = Tag.SvtType as const;
get value() {
return new SqType(valueMethod(this, RSValue.getType));
}
}
export class SqTypeIdentifierValue extends SqAbstractValue {
tag = Tag.SvtTypeIdentifier as const;
get value() {
return valueMethod(this, RSValue.getTypeIdentifier);
}
}
export class SqVoidValue extends SqAbstractValue {
tag = Tag.SvtVoid as const;
}
const tagToClass = {
[Tag.SvtArray]: SqArrayValue,
[Tag.SvtArrayString]: SqArrayStringValue,
[Tag.SvtBool]: SqBoolValue,
[Tag.SvtCall]: SqCallValue,
[Tag.SvtDate]: SqDateValue,
[Tag.SvtDeclaration]: SqDeclarationValue,
[Tag.SvtDistribution]: SqDistributionValue,
[Tag.SvtLambda]: SqLambdaValue,
[Tag.SvtModule]: SqModuleValue,
[Tag.SvtNumber]: SqNumberValue,
[Tag.SvtRecord]: SqRecordValue,
[Tag.SvtString]: SqStringValue,
[Tag.SvtSymbol]: SqSymbolValue,
[Tag.SvtTimeDuration]: SqTimeDurationValue,
[Tag.SvtType]: SqTypeValue,
[Tag.SvtTypeIdentifier]: SqTypeIdentifierValue,
[Tag.SvtVoid]: SqVoidValue,
} as const;
// FIXME
// type SqValue = typeof tagToClass[keyof typeof tagToClass];
export type SqValue =
| SqArrayValue
| SqArrayStringValue
| SqBoolValue
| SqCallValue
| SqDateValue
| SqDeclarationValue
| SqDistributionValue
| SqLambdaValue
| SqModuleValue
| SqNumberValue
| SqRecordValue
| SqStringValue
| SqSymbolValue
| SqTimeDurationValue
| SqTypeValue
| SqTypeIdentifierValue
| SqVoidValue;

View File

@ -1,212 +0,0 @@
import * as RSSquiggleValue from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue.gen";
import { squiggleValueTag as Tag } from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_tag";
import { wrapDistribution } from "./Distribution";
import { Lambda } from "./Lambda";
import { LambdaDeclaration } from "./LambdaDeclaration";
import { NameSpace } from "./NameSpace";
import { Record } from "./Record";
import { SquiggleArray } from "./SquiggleArray";
import { Type } from "./Type";
export { Tag };
type T = RSSquiggleValue.squiggleValue;
export const wrapSquiggleValue = (value: T): SquiggleValue => {
const tag = RSSquiggleValue.getTag(value);
return new tagToClass[tag](value);
};
export abstract class AbstractSquiggleValue {
abstract tag: Tag;
_value: T;
constructor(value: T) {
this._value = value;
}
}
const valueMethod = <IR>(
_this: AbstractSquiggleValue,
rsMethod: (v: T) => IR | null | undefined
) => {
const value = rsMethod(_this._value);
if (!value) throw new Error("Internal casting error");
return value;
};
export class ArrayValue extends AbstractSquiggleValue {
tag = Tag.SvtArray as const;
get value() {
return new SquiggleArray(valueMethod(this, RSSquiggleValue.getArray));
}
}
export class ArrayStringValue extends AbstractSquiggleValue {
tag = Tag.SvtArrayString as const;
get value() {
return valueMethod(this, RSSquiggleValue.getArrayString);
}
}
export class BoolValue extends AbstractSquiggleValue {
tag = Tag.SvtBool as const;
get value() {
return valueMethod(this, RSSquiggleValue.getBool);
}
}
export class CallValue extends AbstractSquiggleValue {
tag = Tag.SvtCall as const;
get value() {
return valueMethod(this, RSSquiggleValue.getCall);
}
}
export class DateValue extends AbstractSquiggleValue {
tag = Tag.SvtDate as const;
get value() {
return valueMethod(this, RSSquiggleValue.getDate);
}
}
export class DeclarationValue extends AbstractSquiggleValue {
tag = Tag.SvtDeclaration as const;
get value() {
return new LambdaDeclaration(
valueMethod(this, RSSquiggleValue.getDeclaration)
);
}
}
export class DistributionValue extends AbstractSquiggleValue {
tag = Tag.SvtDistribution as const;
get value() {
return wrapDistribution(valueMethod(this, RSSquiggleValue.getDistribution));
}
}
export class LambdaValue extends AbstractSquiggleValue {
tag = Tag.SvtLambda as const;
get value() {
return new Lambda(valueMethod(this, RSSquiggleValue.getLambda));
}
}
export class ModuleValue extends AbstractSquiggleValue {
tag = Tag.SvtModule as const;
get value() {
return new NameSpace(valueMethod(this, RSSquiggleValue.getModule));
}
}
export class NumberValue extends AbstractSquiggleValue {
tag = Tag.SvtNumber as const;
get value() {
return valueMethod(this, RSSquiggleValue.getNumber);
}
}
export class RecordValue extends AbstractSquiggleValue {
tag = Tag.SvtRecord as const;
get value() {
return new Record(valueMethod(this, RSSquiggleValue.getRecord));
}
}
export class StringValue extends AbstractSquiggleValue {
tag = Tag.SvtString as const;
get value(): string {
return valueMethod(this, RSSquiggleValue.getString);
}
}
export class SymbolValue extends AbstractSquiggleValue {
tag = Tag.SvtSymbol as const;
get value(): string {
return valueMethod(this, RSSquiggleValue.getSymbol);
}
}
export class TimeDurationValue extends AbstractSquiggleValue {
tag = Tag.SvtTimeDuration as const;
get value() {
return valueMethod(this, RSSquiggleValue.getTimeDuration);
}
}
export class TypeValue extends AbstractSquiggleValue {
tag = Tag.SvtType as const;
get value() {
return new Type(valueMethod(this, RSSquiggleValue.getType));
}
}
export class TypeIdentifierValue extends AbstractSquiggleValue {
tag = Tag.SvtTypeIdentifier as const;
get value() {
return valueMethod(this, RSSquiggleValue.getTypeIdentifier);
}
}
export class VoidValue extends AbstractSquiggleValue {
tag = Tag.SvtVoid as const;
}
const tagToClass = {
[Tag.SvtArray]: ArrayValue,
[Tag.SvtArrayString]: ArrayStringValue,
[Tag.SvtBool]: BoolValue,
[Tag.SvtCall]: CallValue,
[Tag.SvtDate]: DateValue,
[Tag.SvtDeclaration]: DeclarationValue,
[Tag.SvtDistribution]: DistributionValue,
[Tag.SvtLambda]: LambdaValue,
[Tag.SvtModule]: ModuleValue,
[Tag.SvtNumber]: NumberValue,
[Tag.SvtRecord]: RecordValue,
[Tag.SvtString]: StringValue,
[Tag.SvtSymbol]: SymbolValue,
[Tag.SvtTimeDuration]: TimeDurationValue,
[Tag.SvtType]: TypeValue,
[Tag.SvtTypeIdentifier]: TypeIdentifierValue,
[Tag.SvtVoid]: VoidValue,
} as const;
// FIXME
// type AnySquiggleValue = typeof tagToClass[keyof typeof tagToClass];
export type SquiggleValue =
| ArrayValue
| ArrayStringValue
| BoolValue
| CallValue
| DateValue
| DeclarationValue
| DistributionValue
| LambdaValue
| ModuleValue
| NumberValue
| RecordValue
| StringValue
| SymbolValue
| TimeDurationValue
| TypeValue
| TypeIdentifierValue
| VoidValue;

View File

@ -1,83 +1,21 @@
/* Some of the types have moved to ForTS__Types.
Needs to be reimported here if necessary and distribution related
We only need distribution related extras for back compatibility. Umur
Instead of a global function namespace we should use modules under ForTS directly maybe renaming them for ease.
.e.g. Project.run(project)
.e.g. Distribution.makeSampleSetDist
*/
import { environment } from "../rescript/ForTS/ForTS_ReducerProject.gen"; import { environment } from "../rescript/ForTS/ForTS_ReducerProject.gen";
import { Project } from "./Project"; import { SqProject } from "./SqProject";
import { SquiggleValue, Tag as SquiggleValueTag } from "./SquiggleValue"; import { SqValue, SqValueTag } from "./SqValue";
export { result } from "../rescript/ForTS/ForTS_Result_tag"; export { result } from "../rescript/ForTS/ForTS_Result_tag";
export { Project, SquiggleValue }; export { SqDistribution, SqDistributionTag } from "./SqDistribution";
export { export { SqDistributionError } from "./SqDistributionError";
Distribution as Distribution, export { SqRecord } from "./SqRecord";
Tag as DistributionTag, export { SqLambda } from "./SqLambda";
} from "./Distribution"; export { SqProject };
export { DistributionError } from "./DistributionError"; export { SqValue, SqValueTag };
export { Record as SquiggleRecord } from "./Record";
export { Lambda } from "./Lambda";
export { SquiggleValueTag };
export { export {
environment, environment,
defaultEnvironment, defaultEnvironment,
} from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution.gen"; } from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution.gen";
export { ErrorValue } from "./ErrorValue"; export { SqError } from "./SqError";
export { SqShape } from "./SqPointSetDist";
export { resultMap } from "./types"; export { resultMap } from "./types";
export { shape } from "./PointSetDist";
// import * as _ from "lodash";
// import type {
// environment,
// expressionValue,
// externalBindings,
// errorValue,
// } from "../rescript/TypescriptInterface.gen";
// import {
// defaultEnvironment,
// evaluatePartialUsingExternalBindings,
// evaluateUsingOptions,
// foreignFunctionInterface,
// } from "../rescript/TypescriptInterface.gen";
// export {
// makeSampleSetDist,
// errorValueToString,
// distributionErrorToString,
// } from "../rescript/TypescriptInterface.gen";
// export type {
// distributionError,
// declarationArg,
// declaration,
// } from "../rescript/TypescriptInterface.gen";
// export type { errorValue, externalBindings as bindings, jsImports };
// import {
// jsValueToBinding,
// jsValueToExpressionValue,
// jsValue,
// rescriptExport,
// squiggleExpression,
// convertRawToTypescript,
// lambdaValue,
// } from "./rescript_interop";
// import { result, resultMap, tag, tagged } from "./types";
// import { Distribution, shape } from "./distribution";
// export { Distribution, resultMap, defaultEnvironment };
// export type { result, shape, environment, lambdaValue, squiggleExpression };
// export { parse } from "./parse";
// export let defaultSamplingInputs: environment = {
// sampleCount: 10000,
// xyPointLength: 10000,
// };
/* Umur: All the functions below are invalid. ForTS_Reducer project is the new way to do this. */
export const run = ( export const run = (
code: string, code: string,
@ -85,7 +23,7 @@ export const run = (
environment?: environment; environment?: environment;
} }
) => { ) => {
const project = Project.create(); const project = SqProject.create();
project.setSource("main", code); project.setSource("main", code);
if (options?.environment) { if (options?.environment) {
project.setEnvironment(options.environment); project.setEnvironment(options.environment);
@ -96,39 +34,15 @@ export const run = (
return { result, bindings }; return { result, bindings };
}; };
// export function run( // import {
// squiggleString: string, // jsValueToBinding,
// bindings?: externalBindings, // jsValueToExpressionValue,
// environment?: environment, // jsValue,
// imports?: jsImports // rescriptExport,
// ): result<squiggleExpression, errorValue> { // squiggleExpression,
// let b = bindings ? bindings : defaultBindings; // convertRawToTypescript,
// let i = imports ? imports : defaultImports; // lambdaValue,
// let e = environment ? environment : defaultEnvironment; // } from "./rescript_interop";
// let res: result<expressionValue, errorValue> = evaluateUsingOptions(
// { externalBindings: mergeImportsWithBindings(b, i), environment: e },
// squiggleString
// );
// return resultMap(res, (x) => createTsExport(x, e));
// }
// // Run Partial. A partial is a block of code that doesn't return a value
// export function runPartial(
// squiggleString: string,
// bindings?: externalBindings,
// environment?: environment,
// imports?: jsImports
// ): result<externalBindings, errorValue> {
// let b = bindings ? bindings : defaultBindings;
// let i = imports ? imports : defaultImports;
// let e = environment ? environment : defaultEnvironment;
// return evaluatePartialUsingExternalBindings(
// squiggleString,
// mergeImportsWithBindings(b, i),
// e
// );
// }
// export function runForeign( // export function runForeign(
// fn: lambdaValue, // fn: lambdaValue,

View File

@ -27,9 +27,3 @@ export function resultMap2<a, b, c, d>(
export function Ok<a, b>(x: a): result<a, b> { export function Ok<a, b>(x: a): result<a, b> {
return { tag: "Ok", value: x }; return { tag: "Ok", value: x };
} }
export type tagged<a, b> = { tag: a; value: b };
export function tag<a, b>(x: a, y: b): tagged<a, b> {
return { tag: x, value: y };
}