diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx
index 1a3c4414..2971a3e1 100644
--- a/packages/components/src/components/SquiggleChart.tsx
+++ b/packages/components/src/components/SquiggleChart.tsx
@@ -11,14 +11,15 @@ import {
defaultImports,
defaultBindings,
defaultEnvironment,
- continuousDeclaration,
+ declarationArg,
+ declaration
} from "@quri/squiggle-lang";
import { NumberShower } from "./NumberShower";
import { DistributionChart } from "./DistributionChart";
import { ErrorBox } from "./ErrorBox";
import { FunctionChart, FunctionChartSettings } from "./FunctionChart";
-function getRange(x: continuousDeclaration) {
+function getRange(x: declaration) {
let first = x.args[0];
switch (first.tag) {
case "Float": {
@@ -30,7 +31,7 @@ function getRange(x: continuousDeclaration) {
}
}
function getChartSettings(
- x: continuousDeclaration
+ x: declaration
): FunctionChartSettings {
let range = getRange(x);
let min = range.floats ? range.floats.min : 0;
@@ -240,27 +241,17 @@ const SquiggleItem: React.FC = ({
/>
);
case "lambdaDeclaration": {
- switch (expression.value.tag) {
- case "Continuous": {
return (
);
- }
- case "RelativeComparison": {
- return <>"Relative">;
- }
- default: {
- return <>LambdaDeclaration: Should be unreachable>;
- }
}
- }
default: {
return <>Should be unreachable>;
}
diff --git a/packages/squiggle-lang/src/js/index.ts b/packages/squiggle-lang/src/js/index.ts
index f06dac99..03068a51 100644
--- a/packages/squiggle-lang/src/js/index.ts
+++ b/packages/squiggle-lang/src/js/index.ts
@@ -14,9 +14,8 @@ export {
errorValueToString,
distributionErrorToString,
distributionError,
- continuousDeclaration,
- relativeComparisonDeclaration,
- declarationContinuousArg,
+ declarationArg,
+ declaration,
} from "../rescript/TypescriptInterface.gen";
export type { errorValue, externalBindings as bindings, jsImports };
import {
diff --git a/packages/squiggle-lang/src/js/rescript_interop.ts b/packages/squiggle-lang/src/js/rescript_interop.ts
index 9d521927..64e7a64f 100644
--- a/packages/squiggle-lang/src/js/rescript_interop.ts
+++ b/packages/squiggle-lang/src/js/rescript_interop.ts
@@ -9,7 +9,8 @@ import {
discreteShape,
continuousShape,
lambdaValue,
- lambdaDeclaration
+ lambdaDeclaration,
+ declarationArg,
} from "../rescript/TypescriptInterface.gen";
import { Distribution } from "./distribution";
import { tagged, tag } from "./types";
@@ -67,7 +68,7 @@ export type rescriptExport =
}
| {
TAG: 12; // EvDeclaration
- _0: lambdaDeclaration;
+ _0: rescriptLambdaDeclaration;
};
type rescriptDist =
@@ -89,6 +90,23 @@ type rescriptPointSetDist =
_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 =
| tagged<"symbol", string>
| tagged<"string", string>
@@ -148,7 +166,21 @@ export function convertRawToTypescript(
case 11: // EvTimeDuration
return tag("number", result._0);
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 });
}
}
diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res
index da5260c6..582df17d 100644
--- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res
+++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res
@@ -78,9 +78,9 @@ module FRType = {
| (FRTypeOption(v), _) => Some(FRValueOption(matchWithExpressionValue(v, r)))
| (FRTypeLambda, EvLambda(f)) => Some(FRValueLambda(f))
| (FRTypeArray(intendedType), EvArray(elements)) => {
- let el = elements->E.A2.fmap(matchWithExpressionValue(intendedType))
- E.A.O.openIfAllSome(el)->E.O2.fmap(r => FRValueArray(r))
- }
+ let el = elements->E.A2.fmap(matchWithExpressionValue(intendedType))
+ E.A.O.openIfAllSome(el)->E.O2.fmap(r => FRValueArray(r))
+ }
| (FRTypeRecord(recordParams), EvRecord(record)) => {
let getAndMatch = (name, input) =>
E.Dict.get(record, name)->E.O.bind(matchWithExpressionValue(input))
@@ -96,23 +96,24 @@ module FRType = {
}
let rec matchReverse = (e: frValue): expressionValue =>
- switch(e){
- | FRValueNumber(f) => (EvNumber(f))
+ switch e {
+ | FRValueNumber(f) => EvNumber(f)
| FRValueDistOrNumber(FRValueNumber(n)) => EvNumber(n)
| FRValueDistOrNumber(FRValueDist(n)) => EvDistribution(n)
| FRValueDist(dist) => EvDistribution(dist)
| FRValueOption(Some(r)) => matchReverse(r)
| FRValueArray(elements) => EvArray(elements->E.A2.fmap(matchReverse))
| FRValueRecord(frValueRecord) => {
- let record = frValueRecord->E.A2.fmap(((name, value)) => (name, matchReverse(value)))->E.Dict.fromArray
- EvRecord(record)
- }
+ let record =
+ frValueRecord->E.A2.fmap(((name, value)) => (name, matchReverse(value)))->E.Dict.fromArray
+ EvRecord(record)
+ }
| FRValueLambda(l) => EvLambda(l)
| FRValueString(string) => EvString(string)
| FRValueVariant(string) => EvString(string)
- }
+ }
- // | FRValueOption(None) => break
+ // | FRValueOption(None) => break
let matchWithExpressionValueArray = (inputs: array, args: array): option<
array,
> => {
diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res
index 39f20d4d..54933d20 100644
--- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res
+++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res
@@ -21,7 +21,7 @@ module Declaration = {
->E.A2.fmap(getMinMax)
->E.A.R.firstErrorOrOpen
->E.R2.fmap(args => ReducerInterface_ExpressionValue.EvDeclaration(
- Declaration.ContinuousDeclaration.make(lambda, args),
+ Declaration.make(lambda, args),
))
}
| _ => Error("Error")
@@ -35,8 +35,7 @@ let registry = [
~definitions=[
FnDefinition.make(~name="declareFn", ~inputs=[Declaration.frType], ~run=(inputs, _) => {
inputs->E.A.unsafe_get(0)->Declaration.fromExpressionValue
- }
- ),
+ }),
],
),
Function.make(
diff --git a/packages/squiggle-lang/src/rescript/TypescriptInterface.res b/packages/squiggle-lang/src/rescript/TypescriptInterface.res
index e6170366..932edaa1 100644
--- a/packages/squiggle-lang/src/rescript/TypescriptInterface.res
+++ b/packages/squiggle-lang/src/rescript/TypescriptInterface.res
@@ -92,13 +92,7 @@ let defaultEnvironment = ReducerInterface_ExpressionValue.defaultEnvironment
let foreignFunctionInterface = Reducer.foreignFunctionInterface
@genType
-type declarationContinuousArg = Declaration.continuousArg
-
-@genType
-type continuousDeclaration<'a> = Declaration.continuousDeclaration<'a>
-
-@genType
-type relativeComparisonDeclaration<'a> = Declaration.relativeComparisonDeclaration<'a>
+type declarationArg = Declaration.arg
@genType
type declaration<'a> = Declaration.declaration<'a>
diff --git a/packages/squiggle-lang/src/rescript/Utility/Declaration.res b/packages/squiggle-lang/src/rescript/Utility/Declaration.res
index 188f01ca..d26e1833 100644
--- a/packages/squiggle-lang/src/rescript/Utility/Declaration.res
+++ b/packages/squiggle-lang/src/rescript/Utility/Declaration.res
@@ -1,33 +1,24 @@
@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
-type continuousDeclaration<'a> = {fn: 'a, args: array}
-@genType
-type relativeComparisonDeclaration<'a> = {fn: 'a, options: array}
-@genType
-type declaration<'a> =
- Continuous(continuousDeclaration<'a>) | RelativeComparison(relativeComparisonDeclaration<'a>)
+type declaration<'a> = {
+ fn: 'a,
+ args: array,
+}
module ContinuousFloatArg = {
- let make = (min: float, max: float): continuousArg => {
+ let make = (min: float, max: float): arg => {
Float({min: min, max: max})
}
}
module ContinuousTimeArg = {
- let make = (min: Js.Date.t, max: Js.Date.t): continuousArg => {
- Time({min: min, max: max})
+ let make = (min: Js.Date.t, max: Js.Date.t): arg => {
+ Date({min: min, max: max})
}
}
-module ContinuousDeclaration = {
- let make = (fn: 'a, args: array): declaration<'a> => {
- Continuous({fn: fn, args: args})
- }
-}
-
-module RelativeComparisonDeclaration = {
- let make = (fn: 'a, options: array): declaration<'a> => {
- RelativeComparison({fn: fn, options: options})
- }
+let make = (fn: 'a, args: array): declaration<'a> => {
+ {fn: fn, args: args}
}