diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_type_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_type_test.res index 05ec5722..e5609aea 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_type_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_type_test.res @@ -88,8 +88,8 @@ describe("Peggy Types to Expression", () => { }) describe("squiggle expressions in type modifiers", () => { testToExpression( - "odds1 = [1,3,5]; odds2 = [7, 9]; type odds = number<-memberOf(odds1 + odds2)", - "{(:$_let_$ :odds1 {(:$_constructArray_$ (1 3 5))}); (:$_let_$ :odds2 {(:$_constructArray_$ (7 9))}); (:$_typeAlias_$ #odds (:$_typeModifier_memberOf_$ #number (:add :odds1 :odds2)))}", + "odds1 = [1,3,5]; odds2 = [7, 9]; type odds = number<-memberOf(concat(odds1, odds2))", + "{(:$_let_$ :odds1 {(:$_constructArray_$ (1 3 5))}); (:$_let_$ :odds2 {(:$_constructArray_$ (7 9))}); (:$_typeAlias_$ #odds (:$_typeModifier_memberOf_$ #number (:concat :odds1 :odds2)))}", ~v="{_typeAliases_: {odds: {typeTag: 'typeIdentifier',typeIdentifier: #number,memberOf: [1,3,5,7,9]}},odds1: [1,3,5],odds2: [7,9]}", (), ) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_mapReduce_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_mapReduce_test.res index 5414f827..f3df0962 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_mapReduce_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_mapReduce_test.res @@ -7,7 +7,7 @@ describe("map reduce", () => { testEvalToBe("change(acc,x)=acc*x+x; arr=[1,2,3]; reduce(arr, 0, change)", "Ok(15)") testEvalToBe("change(acc,x)=acc*x+x; arr=[1,2,3]; reduceReverse(arr, 0, change)", "Ok(9)") testEvalToBe("arr=[1,2,3]; reverse(arr)", "Ok([3,2,1])") - testEvalToBe("check(x)=(x==2);arr=[1,2,3]; keep(arr,check)", "Ok([2])") + testEvalToBe("check(x)=(x==2);arr=[1,2,3]; filter(arr,check)", "Ok([2])") }) Skip.describe("map reduce (sam)", () => { diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res index d1ef1359..22323e80 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res @@ -350,7 +350,7 @@ module Function = { description: description, } - let toSimple = (t: t): functionJson => { + let toJson = (t: t): functionJson => { name: t.name, definitions: t.definitions->E.A2.fmap(FnDefinition.toString), examples: t.examples, @@ -360,7 +360,7 @@ module Function = { } module Registry = { - let toSimple = (r: registry) => r->E.A2.fmap(Function.toSimple) + let toJson = (r: registry) => r->E.A2.fmap(Function.toJson) /* There's a (potential+minor) bug here: If a function definition is called outside of the calls @@ -374,7 +374,7 @@ module Registry = { ~env: DistributionOperation.env, ) => { let matchToDef = m => Matcher.Registry.matchToDef(registry, m) - Js.log(toSimple(registry)) + //Js.log(toSimple(registry)) let showNameMatchDefinitions = matches => { let defs = matches diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_Duration.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_Duration.res index f6322fc4..b11eda89 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_Duration.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_Duration.res @@ -27,8 +27,7 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option< EV.EvTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some | ("divide", [EvTimeDuration(d1), EvNumber(d2)]) => EV.EvTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some - | ("divide", [EvTimeDuration(d1), EvTimeDuration(d2)]) => - EV.EvNumber(d1 /. d2)->Ok->Some + | ("divide", [EvTimeDuration(d1), EvTimeDuration(d2)]) => EV.EvNumber(d1 /. d2)->Ok->Some | _ => None } } diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res index 2b49439a..6ef3f7a6 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res @@ -277,8 +277,7 @@ let dispatchToGenericOutput = ( Helpers.toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist, ~env) | ("toSampleSet", [EvDistribution(dist)]) => Helpers.toDistFn(ToSampleSet(env.sampleCount), dist, ~env) - | ("toList", [EvDistribution(SampleSet(dist))]) => - Some(FloatArray(SampleSetDist.T.get(dist))) + | ("toList", [EvDistribution(SampleSet(dist))]) => Some(FloatArray(SampleSetDist.T.get(dist))) | ("fromSamples", [EvArray(inputArray)]) => { let _wrapInputErrors = x => SampleSetDist.NonNumericInput(x) let parsedArray = Helpers.parseNumberArray(inputArray)->E.R2.errMap(_wrapInputErrors) diff --git a/packages/website/docs/Api/DistGeneric.mdx b/packages/website/docs/Api/DistGeneric.mdx index 859f53db..17dfdc4e 100644 --- a/packages/website/docs/Api/DistGeneric.mdx +++ b/packages/website/docs/Api/DistGeneric.mdx @@ -14,15 +14,15 @@ import TOCInline from "@theme/TOCInline"; **Definitions** ```javascript -normal: (frValueDistOrNumber, frValueDistOrNumber); +normal: (frValueDistOrNumber, frValueDistOrNumber) => distribution; ``` ```javascript -normal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) +normal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) => distribution ``` ```javascript -normal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) +normal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) => distribution ``` **Examples** @@ -38,15 +38,15 @@ normal({ mean: 5, stdev: 2 }); **Definitions** ```javascript -lognormal: (frValueDistOrNumber, frValueDistOrNumber); +lognormal: (frValueDistOrNumber, frValueDistOrNumber) => distribution; ``` ```javascript -lognormal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) +lognormal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) => distribution ``` ```javascript -lognormal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) +lognormal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) => distribution ``` **Examples** @@ -62,7 +62,7 @@ lognormal({ mean: 5, stdev: 2 }); **Definitions** ```javascript -uniform: (frValueDistOrNumber, frValueDistOrNumber); +uniform: (frValueDistOrNumber, frValueDistOrNumber) => distribution; ``` **Examples** @@ -76,7 +76,7 @@ uniform(10, 12); **Definitions** ```javascript -beta: (frValueDistOrNumber, frValueDistOrNumber); +beta: (frValueDistOrNumber, frValueDistOrNumber) => distribution; ``` **Examples** @@ -90,7 +90,7 @@ beta(20, 25); **Definitions** ```javascript -cauchy: (frValueDistOrNumber, frValueDistOrNumber); +cauchy: (frValueDistOrNumber, frValueDistOrNumber) => distribution; ``` **Examples** @@ -104,7 +104,7 @@ cauchy(5, 1); **Definitions** ```javascript -gamma: (frValueDistOrNumber, frValueDistOrNumber); +gamma: (frValueDistOrNumber, frValueDistOrNumber) => distribution; ``` **Examples** @@ -118,7 +118,7 @@ gamma(5, 1); **Definitions** ```javascript -logistic: (frValueDistOrNumber, frValueDistOrNumber); +logistic: (frValueDistOrNumber, frValueDistOrNumber) => distribution; ``` **Examples** @@ -132,11 +132,11 @@ gamma(5, 1); **Definitions** ```javascript -to: (frValueDistOrNumber, frValueDistOrNumber); +to: (frValueDistOrNumber, frValueDistOrNumber) => distribution; ``` ```javascript -credibleIntervalToDistribution(frValueDistOrNumber, frValueDistOrNumber); +credibleIntervalToDistribution(frValueDistOrNumber, frValueDistOrNumber) => distribution; ``` **Examples** @@ -152,7 +152,7 @@ to(5,10) **Definitions** ```javascript -exponential: (frValueDistOrNumber); +exponential: (frValueDistOrNumber) => distribution; ``` **Examples** @@ -166,7 +166,7 @@ exponential(2); **Definitions** ```javascript -bernoulli: (frValueDistOrNumber); +bernoulli: (frValueDistOrNumber) => distribution; ``` **Examples** @@ -182,7 +182,7 @@ Converts a set of points to a continuous distribution **Definitions** ```javascript -toContinuousPointSet: (array>) +toContinuousPointSet: (array>) => distribution ``` **Examples** @@ -203,7 +203,7 @@ Converts a set of points to a discrete distribution **Definitions** ```javascript -toDiscretePointSet: (array>) +toDiscretePointSet: (array>) => distribution ``` **Examples** @@ -251,7 +251,7 @@ sample(normal(5, 2)); Get n random samples from the distribution ```javascript -sampleN: (distribution, number):list +sampleN: (distribution, number) => list ``` **Examples** @@ -313,7 +313,7 @@ pdf: (distribution, number) => number **Examples** ```javascript -pdf: (normal(5, 2), 3); +pdf(normal(5, 2), 3); ``` ### inv @@ -333,7 +333,7 @@ inv(normal(5, 2), 0.5); Converts a distribution to the pointSet format ```javascript -toPointSet: (distribution):pointSetDistribution +toPointSet: (distribution) => pointSetDistribution ``` **Examples** @@ -347,7 +347,7 @@ toPointSet(normal(5, 2)); Converts a distribution to the sampleSet format, with n samples ```javascript -toSampleSet: (distribution,number):sampleSetDistribution +toSampleSet: (distribution,number) => sampleSetDistribution ``` **Examples** @@ -405,7 +405,7 @@ klDivergence(normal(5, 2), normal(5, 4)); // returns 0.57 ### toString ```javascript -: (distribution) => string +toString: (distribution) => string ``` **Examples** @@ -463,7 +463,7 @@ normalize(normal(5, 2)); Check of a distribution is normalized. Most distributions are typically normalized, but there are some commands that could produce non-normalized distributions. ```javascript -isNormalized: (distribution):bool +isNormalized: (distribution) => bool ``` **Examples** @@ -631,7 +631,7 @@ scaleLog10: (distributionLike, number) => distribution Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within. ```javascript -declareFn: (dict<{fn: lambda, inputs: array>}>) +declareFn: (dict<{fn: lambda, inputs: array>}>) => declaration ``` **Examples**