Fixed bug caused by bad genType format of Declaration
This commit is contained in:
parent
3404534b10
commit
298d3923bc
|
@ -11,14 +11,15 @@ import {
|
||||||
defaultImports,
|
defaultImports,
|
||||||
defaultBindings,
|
defaultBindings,
|
||||||
defaultEnvironment,
|
defaultEnvironment,
|
||||||
continuousDeclaration,
|
declarationArg,
|
||||||
|
declaration
|
||||||
} from "@quri/squiggle-lang";
|
} from "@quri/squiggle-lang";
|
||||||
import { NumberShower } from "./NumberShower";
|
import { NumberShower } from "./NumberShower";
|
||||||
import { DistributionChart } from "./DistributionChart";
|
import { DistributionChart } from "./DistributionChart";
|
||||||
import { ErrorBox } from "./ErrorBox";
|
import { ErrorBox } from "./ErrorBox";
|
||||||
import { FunctionChart, FunctionChartSettings } from "./FunctionChart";
|
import { FunctionChart, FunctionChartSettings } from "./FunctionChart";
|
||||||
|
|
||||||
function getRange<a>(x: continuousDeclaration<a>) {
|
function getRange<a>(x: declaration<a>) {
|
||||||
let first = x.args[0];
|
let first = x.args[0];
|
||||||
switch (first.tag) {
|
switch (first.tag) {
|
||||||
case "Float": {
|
case "Float": {
|
||||||
|
@ -30,7 +31,7 @@ function getRange<a>(x: continuousDeclaration<a>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getChartSettings<a>(
|
function getChartSettings<a>(
|
||||||
x: continuousDeclaration<a>
|
x: declaration<a>
|
||||||
): FunctionChartSettings {
|
): FunctionChartSettings {
|
||||||
let range = getRange(x);
|
let range = getRange(x);
|
||||||
let min = range.floats ? range.floats.min : 0;
|
let min = range.floats ? range.floats.min : 0;
|
||||||
|
@ -240,12 +241,10 @@ const SquiggleItem: React.FC<SquiggleItemProps> = ({
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case "lambdaDeclaration": {
|
case "lambdaDeclaration": {
|
||||||
switch (expression.value.tag) {
|
|
||||||
case "Continuous": {
|
|
||||||
return (
|
return (
|
||||||
<FunctionChart
|
<FunctionChart
|
||||||
fn={expression.value.value.fn}
|
fn={expression.value.fn}
|
||||||
chartSettings={getChartSettings(expression.value.value)}
|
chartSettings={getChartSettings(expression.value)}
|
||||||
environment={{
|
environment={{
|
||||||
sampleCount: environment.sampleCount / 10,
|
sampleCount: environment.sampleCount / 10,
|
||||||
xyPointLength: environment.xyPointLength / 10,
|
xyPointLength: environment.xyPointLength / 10,
|
||||||
|
@ -253,14 +252,6 @@ const SquiggleItem: React.FC<SquiggleItemProps> = ({
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case "RelativeComparison": {
|
|
||||||
return <>"Relative"</>;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return <>LambdaDeclaration: Should be unreachable</>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default: {
|
default: {
|
||||||
return <>Should be unreachable</>;
|
return <>Should be unreachable</>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,8 @@ export {
|
||||||
errorValueToString,
|
errorValueToString,
|
||||||
distributionErrorToString,
|
distributionErrorToString,
|
||||||
distributionError,
|
distributionError,
|
||||||
continuousDeclaration,
|
declarationArg,
|
||||||
relativeComparisonDeclaration,
|
declaration,
|
||||||
declarationContinuousArg,
|
|
||||||
} from "../rescript/TypescriptInterface.gen";
|
} from "../rescript/TypescriptInterface.gen";
|
||||||
export type { errorValue, externalBindings as bindings, jsImports };
|
export type { errorValue, externalBindings as bindings, jsImports };
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -9,7 +9,8 @@ import {
|
||||||
discreteShape,
|
discreteShape,
|
||||||
continuousShape,
|
continuousShape,
|
||||||
lambdaValue,
|
lambdaValue,
|
||||||
lambdaDeclaration
|
lambdaDeclaration,
|
||||||
|
declarationArg,
|
||||||
} from "../rescript/TypescriptInterface.gen";
|
} from "../rescript/TypescriptInterface.gen";
|
||||||
import { Distribution } from "./distribution";
|
import { Distribution } from "./distribution";
|
||||||
import { tagged, tag } from "./types";
|
import { tagged, tag } from "./types";
|
||||||
|
@ -67,7 +68,7 @@ export type rescriptExport =
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
TAG: 12; // EvDeclaration
|
TAG: 12; // EvDeclaration
|
||||||
_0: lambdaDeclaration;
|
_0: rescriptLambdaDeclaration;
|
||||||
};
|
};
|
||||||
|
|
||||||
type rescriptDist =
|
type rescriptDist =
|
||||||
|
@ -89,6 +90,23 @@ type rescriptPointSetDist =
|
||||||
_0: continuousShape;
|
_0: continuousShape;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type rescriptLambdaDeclaration = {
|
||||||
|
readonly fn: lambdaValue;
|
||||||
|
readonly args: rescriptDeclarationArg[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type rescriptDeclarationArg =
|
||||||
|
| {
|
||||||
|
TAG: 0; // Float
|
||||||
|
min: number;
|
||||||
|
max: number;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
TAG: 1; // Float
|
||||||
|
min: Date;
|
||||||
|
max: Date;
|
||||||
|
};
|
||||||
|
|
||||||
export type squiggleExpression =
|
export type squiggleExpression =
|
||||||
| tagged<"symbol", string>
|
| tagged<"symbol", string>
|
||||||
| tagged<"string", string>
|
| tagged<"string", string>
|
||||||
|
@ -148,7 +166,21 @@ export function convertRawToTypescript(
|
||||||
case 11: // EvTimeDuration
|
case 11: // EvTimeDuration
|
||||||
return tag("number", result._0);
|
return tag("number", result._0);
|
||||||
case 12: // EvDeclaration
|
case 12: // EvDeclaration
|
||||||
return tag("lambdaDeclaration", result._0);
|
return tag("lambdaDeclaration", {
|
||||||
|
fn: result._0.fn,
|
||||||
|
args: result._0.args.map(convertDeclaration),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertDeclaration(
|
||||||
|
declarationArg: rescriptDeclarationArg
|
||||||
|
): declarationArg {
|
||||||
|
switch (declarationArg.TAG) {
|
||||||
|
case 0: // Float
|
||||||
|
return tag("Float", { min: declarationArg.min, max: declarationArg.max });
|
||||||
|
case 1: // Date
|
||||||
|
return tag("Date", { min: declarationArg.min, max: declarationArg.max });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,15 +96,16 @@ module FRType = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let rec matchReverse = (e: frValue): expressionValue =>
|
let rec matchReverse = (e: frValue): expressionValue =>
|
||||||
switch(e){
|
switch e {
|
||||||
| FRValueNumber(f) => (EvNumber(f))
|
| FRValueNumber(f) => EvNumber(f)
|
||||||
| FRValueDistOrNumber(FRValueNumber(n)) => EvNumber(n)
|
| FRValueDistOrNumber(FRValueNumber(n)) => EvNumber(n)
|
||||||
| FRValueDistOrNumber(FRValueDist(n)) => EvDistribution(n)
|
| FRValueDistOrNumber(FRValueDist(n)) => EvDistribution(n)
|
||||||
| FRValueDist(dist) => EvDistribution(dist)
|
| FRValueDist(dist) => EvDistribution(dist)
|
||||||
| FRValueOption(Some(r)) => matchReverse(r)
|
| FRValueOption(Some(r)) => matchReverse(r)
|
||||||
| FRValueArray(elements) => EvArray(elements->E.A2.fmap(matchReverse))
|
| FRValueArray(elements) => EvArray(elements->E.A2.fmap(matchReverse))
|
||||||
| FRValueRecord(frValueRecord) => {
|
| FRValueRecord(frValueRecord) => {
|
||||||
let record = frValueRecord->E.A2.fmap(((name, value)) => (name, matchReverse(value)))->E.Dict.fromArray
|
let record =
|
||||||
|
frValueRecord->E.A2.fmap(((name, value)) => (name, matchReverse(value)))->E.Dict.fromArray
|
||||||
EvRecord(record)
|
EvRecord(record)
|
||||||
}
|
}
|
||||||
| FRValueLambda(l) => EvLambda(l)
|
| FRValueLambda(l) => EvLambda(l)
|
||||||
|
|
|
@ -21,7 +21,7 @@ module Declaration = {
|
||||||
->E.A2.fmap(getMinMax)
|
->E.A2.fmap(getMinMax)
|
||||||
->E.A.R.firstErrorOrOpen
|
->E.A.R.firstErrorOrOpen
|
||||||
->E.R2.fmap(args => ReducerInterface_ExpressionValue.EvDeclaration(
|
->E.R2.fmap(args => ReducerInterface_ExpressionValue.EvDeclaration(
|
||||||
Declaration.ContinuousDeclaration.make(lambda, args),
|
Declaration.make(lambda, args),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
| _ => Error("Error")
|
| _ => Error("Error")
|
||||||
|
@ -35,8 +35,7 @@ let registry = [
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(~name="declareFn", ~inputs=[Declaration.frType], ~run=(inputs, _) => {
|
FnDefinition.make(~name="declareFn", ~inputs=[Declaration.frType], ~run=(inputs, _) => {
|
||||||
inputs->E.A.unsafe_get(0)->Declaration.fromExpressionValue
|
inputs->E.A.unsafe_get(0)->Declaration.fromExpressionValue
|
||||||
}
|
}),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Function.make(
|
Function.make(
|
||||||
|
|
|
@ -92,13 +92,7 @@ let defaultEnvironment = ReducerInterface_ExpressionValue.defaultEnvironment
|
||||||
let foreignFunctionInterface = Reducer.foreignFunctionInterface
|
let foreignFunctionInterface = Reducer.foreignFunctionInterface
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
type declarationContinuousArg = Declaration.continuousArg
|
type declarationArg = Declaration.arg
|
||||||
|
|
||||||
@genType
|
|
||||||
type continuousDeclaration<'a> = Declaration.continuousDeclaration<'a>
|
|
||||||
|
|
||||||
@genType
|
|
||||||
type relativeComparisonDeclaration<'a> = Declaration.relativeComparisonDeclaration<'a>
|
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
type declaration<'a> = Declaration.declaration<'a>
|
type declaration<'a> = Declaration.declaration<'a>
|
||||||
|
|
|
@ -1,33 +1,24 @@
|
||||||
@genType
|
@genType
|
||||||
type continuousArg = Float({min: float, max: float}) | Time({min: Js.Date.t, max: Js.Date.t})
|
type arg = Float({min: float, max: float}) | Date({min: Js.Date.t, max: Js.Date.t})
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
type continuousDeclaration<'a> = {fn: 'a, args: array<continuousArg>}
|
type declaration<'a> = {
|
||||||
@genType
|
fn: 'a,
|
||||||
type relativeComparisonDeclaration<'a> = {fn: 'a, options: array<string>}
|
args: array<arg>,
|
||||||
@genType
|
}
|
||||||
type declaration<'a> =
|
|
||||||
Continuous(continuousDeclaration<'a>) | RelativeComparison(relativeComparisonDeclaration<'a>)
|
|
||||||
|
|
||||||
module ContinuousFloatArg = {
|
module ContinuousFloatArg = {
|
||||||
let make = (min: float, max: float): continuousArg => {
|
let make = (min: float, max: float): arg => {
|
||||||
Float({min: min, max: max})
|
Float({min: min, max: max})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module ContinuousTimeArg = {
|
module ContinuousTimeArg = {
|
||||||
let make = (min: Js.Date.t, max: Js.Date.t): continuousArg => {
|
let make = (min: Js.Date.t, max: Js.Date.t): arg => {
|
||||||
Time({min: min, max: max})
|
Date({min: min, max: max})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module ContinuousDeclaration = {
|
let make = (fn: 'a, args: array<arg>): declaration<'a> => {
|
||||||
let make = (fn: 'a, args: array<continuousArg>): declaration<'a> => {
|
{fn: fn, args: args}
|
||||||
Continuous({fn: fn, args: args})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module RelativeComparisonDeclaration = {
|
|
||||||
let make = (fn: 'a, options: array<string>): declaration<'a> => {
|
|
||||||
RelativeComparison({fn: fn, options: options})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user