3-arg fnDefinition
This commit is contained in:
parent
a4fd10e1fb
commit
9f103f5cbe
|
@ -14,7 +14,7 @@ let makeFnMany = (name: string, definitions: array<simpleDefinition>) =>
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
~requiresNamespace=false,
|
~requiresNamespace=false,
|
||||||
~definitions=definitions->Js.Array2.map(({inputs, fn}) =>
|
~definitions=definitions->Js.Array2.map(({inputs, fn}) =>
|
||||||
FnDefinition.make(~name, ~inputs, ~run=(inputs, _, _, _) => fn(inputs), ())
|
FnDefinition.make(~name, ~inputs, ~run=(inputs, _, _) => fn(inputs), ())
|
||||||
),
|
),
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -165,7 +165,7 @@ module Integration = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="integrateFunctionBetweenWithNumIntegrationPoints",
|
~name="integrateFunctionBetweenWithNumIntegrationPoints",
|
||||||
~inputs=[FRTypeLambda, FRTypeNumber, FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeLambda, FRTypeNumber, FRTypeNumber, FRTypeNumber],
|
||||||
~run=(inputs, _, env, reducer) => {
|
~run=(inputs, env, reducer) => {
|
||||||
let result = switch inputs {
|
let result = switch inputs {
|
||||||
| [_, _, _, IEvNumber(0.0)] =>
|
| [_, _, _, IEvNumber(0.0)] =>
|
||||||
"Integration error 4 in Danger.integrate: Increment can't be 0."
|
"Integration error 4 in Danger.integrate: Increment can't be 0."
|
||||||
|
@ -209,7 +209,7 @@ module Integration = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="integrateFunctionBetweenWithEpsilon",
|
~name="integrateFunctionBetweenWithEpsilon",
|
||||||
~inputs=[FRTypeLambda, FRTypeNumber, FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeLambda, FRTypeNumber, FRTypeNumber, FRTypeNumber],
|
||||||
~run=(inputs, _, env, reducer) => {
|
~run=(inputs, env, reducer) => {
|
||||||
let result = switch inputs {
|
let result = switch inputs {
|
||||||
| [_, _, _, IEvNumber(0.0)] =>
|
| [_, _, _, IEvNumber(0.0)] =>
|
||||||
"Integration error in Danger.integrate: Increment can't be 0."
|
"Integration error in Danger.integrate: Increment can't be 0."
|
||||||
|
@ -403,7 +403,7 @@ module DiminishingReturns = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions",
|
~name="optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions",
|
||||||
~inputs=[FRTypeArray(FRTypeLambda), FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeArray(FRTypeLambda), FRTypeNumber, FRTypeNumber],
|
||||||
~run=(inputs, _, environment, reducer) =>
|
~run=(inputs, environment, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(innerlambdas), IEvNumber(funds), IEvNumber(approximateIncrement)] => {
|
| [IEvArray(innerlambdas), IEvNumber(funds), IEvNumber(approximateIncrement)] => {
|
||||||
let individuallyWrappedLambdas = E.A.fmap(innerLambda => {
|
let individuallyWrappedLambdas = E.A.fmap(innerLambda => {
|
||||||
|
|
|
@ -10,7 +10,7 @@ let makeFn = (
|
||||||
~name,
|
~name,
|
||||||
~nameSpace="",
|
~nameSpace="",
|
||||||
~requiresNamespace=false,
|
~requiresNamespace=false,
|
||||||
~definitions=[FnDefinition.make(~name, ~inputs, ~run=(inputs, _, _, _) => fn(inputs), ())],
|
~definitions=[FnDefinition.make(~name, ~inputs, ~run=(inputs, _, _) => fn(inputs), ())],
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ let makeNumberToDurationFn = (name: string, fn: float => DateTime.Duration.t) =>
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeNumber],
|
~inputs=[FRTypeNumber],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvNumber(t)] => IEvTimeDuration(fn(t))->Ok
|
| [IEvNumber(t)] => IEvTimeDuration(fn(t))->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -43,7 +43,7 @@ let makeDurationToNumberFn = (name: string, fn: DateTime.Duration.t => float) =>
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeTimeDuration],
|
~inputs=[FRTypeTimeDuration],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvTimeDuration(t)] => IEvNumber(fn(t))->Ok
|
| [IEvTimeDuration(t)] => IEvNumber(fn(t))->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
|
|
@ -48,7 +48,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="merge",
|
~name="merge",
|
||||||
~inputs=[FRTypeDict(FRTypeAny), FRTypeDict(FRTypeAny)],
|
~inputs=[FRTypeDict(FRTypeAny), FRTypeDict(FRTypeAny)],
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvRecord(d1), IEvRecord(d2)] => Internals.mergeMany([d1, d2])->Ok
|
| [IEvRecord(d1), IEvRecord(d2)] => Internals.mergeMany([d1, d2])->Ok
|
||||||
| _ => impossibleError->Error
|
| _ => impossibleError->Error
|
||||||
|
@ -70,7 +70,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="mergeMany",
|
~name="mergeMany",
|
||||||
~inputs=[FRTypeArray(FRTypeDict(FRTypeAny))],
|
~inputs=[FRTypeArray(FRTypeDict(FRTypeAny))],
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(dicts)] => {
|
| [IEvArray(dicts)] => {
|
||||||
dicts->Belt.Array.map(dictValue => switch dictValue {
|
dicts->Belt.Array.map(dictValue => switch dictValue {
|
||||||
|
@ -96,7 +96,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="keys",
|
~name="keys",
|
||||||
~inputs=[FRTypeDict(FRTypeAny)],
|
~inputs=[FRTypeDict(FRTypeAny)],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvRecord(d1)] => Internals.keys(d1)->Ok
|
| [IEvRecord(d1)] => Internals.keys(d1)->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -116,7 +116,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="values",
|
~name="values",
|
||||||
~inputs=[FRTypeDict(FRTypeAny)],
|
~inputs=[FRTypeDict(FRTypeAny)],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvRecord(d1)] => Internals.values(d1)->Ok
|
| [IEvRecord(d1)] => Internals.values(d1)->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -136,7 +136,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="toList",
|
~name="toList",
|
||||||
~inputs=[FRTypeDict(FRTypeAny)],
|
~inputs=[FRTypeDict(FRTypeAny)],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvRecord(dict)] => dict->Internals.toList->Ok
|
| [IEvRecord(dict)] => dict->Internals.toList->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -156,7 +156,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="fromList",
|
~name="fromList",
|
||||||
~inputs=[FRTypeArray(FRTypeArray(FRTypeAny))],
|
~inputs=[FRTypeArray(FRTypeArray(FRTypeAny))],
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(items)] => Internals.fromList(items)
|
| [IEvArray(items)] => Internals.fromList(items)
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
|
|
@ -22,7 +22,7 @@ module DistributionCreation = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeDistOrNumber, FRTypeDistOrNumber],
|
~inputs=[FRTypeDistOrNumber, FRTypeDistOrNumber],
|
||||||
~run=(inputs, _, env, _) =>
|
~run=(inputs, env, _) =>
|
||||||
inputs->Prepare.ToValueTuple.twoDistOrNumber->process(~fn, ~env),
|
inputs->Prepare.ToValueTuple.twoDistOrNumber->process(~fn, ~env),
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
|
@ -32,7 +32,7 @@ module DistributionCreation = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeRecord([("p5", FRTypeDistOrNumber), ("p95", FRTypeDistOrNumber)])],
|
~inputs=[FRTypeRecord([("p5", FRTypeDistOrNumber), ("p95", FRTypeDistOrNumber)])],
|
||||||
~run=(inputs, _, env, _) =>
|
~run=(inputs, env, _) =>
|
||||||
inputs->Prepare.ToValueTuple.Record.twoDistOrNumber(("p5", "p95"))->process(~fn, ~env),
|
inputs->Prepare.ToValueTuple.Record.twoDistOrNumber(("p5", "p95"))->process(~fn, ~env),
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
|
@ -42,7 +42,7 @@ module DistributionCreation = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeRecord([("mean", FRTypeDistOrNumber), ("stdev", FRTypeDistOrNumber)])],
|
~inputs=[FRTypeRecord([("mean", FRTypeDistOrNumber), ("stdev", FRTypeDistOrNumber)])],
|
||||||
~run=(inputs, _, env, _) =>
|
~run=(inputs, env, _) =>
|
||||||
inputs->Prepare.ToValueTuple.Record.twoDistOrNumber(("mean", "stdev"))->process(~fn, ~env),
|
inputs->Prepare.ToValueTuple.Record.twoDistOrNumber(("mean", "stdev"))->process(~fn, ~env),
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
|
@ -60,7 +60,7 @@ module DistributionCreation = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeDistOrNumber],
|
~inputs=[FRTypeDistOrNumber],
|
||||||
~run=(inputs, _, env, _) =>
|
~run=(inputs, env, _) =>
|
||||||
inputs->Prepare.ToValueTuple.oneDistOrNumber->process(~fn, ~env),
|
inputs->Prepare.ToValueTuple.oneDistOrNumber->process(~fn, ~env),
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -49,7 +49,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="declare",
|
~name="declare",
|
||||||
~inputs=[Declaration.frType],
|
~inputs=[Declaration.frType],
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
inputs->getOrError(0)->E.R.bind(Declaration.fromExpressionValue)->E.R2.errMap(wrapError)
|
inputs->getOrError(0)->E.R.bind(Declaration.fromExpressionValue)->E.R2.errMap(wrapError)
|
||||||
},
|
},
|
||||||
(),
|
(),
|
||||||
|
|
|
@ -326,7 +326,7 @@ let makeProxyFn = (name: string, inputs: array<frType>) => {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs,
|
~inputs,
|
||||||
~run=(inputs, _, env, _) => Old.dispatch((name, inputs), env),
|
~run=(inputs, env, _) => Old.dispatch((name, inputs), env),
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -86,7 +86,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="make",
|
~name="make",
|
||||||
~inputs=[FRTypeNumber, FRTypeAny],
|
~inputs=[FRTypeNumber, FRTypeAny],
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvNumber(number), value] => Internals.makeFromNumber(number, value)->Ok
|
| [IEvNumber(number), value] => Internals.makeFromNumber(number, value)->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -107,7 +107,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="upTo",
|
~name="upTo",
|
||||||
~inputs=[FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeNumber, FRTypeNumber],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvNumber(low), IEvNumber(high)] => Internals.upTo(low, high)->Ok
|
| [IEvNumber(low), IEvNumber(high)] => Internals.upTo(low, high)->Ok
|
||||||
| _ => impossibleError->Error
|
| _ => impossibleError->Error
|
||||||
|
@ -126,7 +126,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="first",
|
~name="first",
|
||||||
~inputs=[FRTypeArray(FRTypeAny)],
|
~inputs=[FRTypeArray(FRTypeAny)],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(array)] => Internals.first(array)->E.R2.errMap(wrapError)
|
| [IEvArray(array)] => Internals.first(array)->E.R2.errMap(wrapError)
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -145,7 +145,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="last",
|
~name="last",
|
||||||
~inputs=[FRTypeArray(FRTypeAny)],
|
~inputs=[FRTypeArray(FRTypeAny)],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(array)] => Internals.last(array)->E.R2.errMap(wrapError)
|
| [IEvArray(array)] => Internals.last(array)->E.R2.errMap(wrapError)
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -165,7 +165,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="reverse",
|
~name="reverse",
|
||||||
~inputs=[FRTypeArray(FRTypeAny)],
|
~inputs=[FRTypeArray(FRTypeAny)],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(array)] => Internals.reverse(array)->Ok
|
| [IEvArray(array)] => Internals.reverse(array)->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -185,7 +185,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="map",
|
~name="map",
|
||||||
~inputs=[FRTypeArray(FRTypeAny), FRTypeLambda],
|
~inputs=[FRTypeArray(FRTypeAny), FRTypeLambda],
|
||||||
~run=(inputs, _, env, reducer) =>
|
~run=(inputs, env, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(array), IEvLambda(lambda)] => Ok(Internals.map(array, lambda, env, reducer))
|
| [IEvArray(array), IEvLambda(lambda)] => Ok(Internals.map(array, lambda, env, reducer))
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -204,7 +204,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="reduce",
|
~name="reduce",
|
||||||
~inputs=[FRTypeArray(FRTypeAny), FRTypeAny, FRTypeLambda],
|
~inputs=[FRTypeArray(FRTypeAny), FRTypeAny, FRTypeLambda],
|
||||||
~run=(inputs, _, env, reducer) =>
|
~run=(inputs, env, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(array), initialValue, IEvLambda(lambda)] =>
|
| [IEvArray(array), initialValue, IEvLambda(lambda)] =>
|
||||||
Ok(Internals.reduce(array, initialValue, lambda, env, reducer))
|
Ok(Internals.reduce(array, initialValue, lambda, env, reducer))
|
||||||
|
@ -224,7 +224,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="reduceReverse",
|
~name="reduceReverse",
|
||||||
~inputs=[FRTypeArray(FRTypeAny), FRTypeAny, FRTypeLambda],
|
~inputs=[FRTypeArray(FRTypeAny), FRTypeAny, FRTypeLambda],
|
||||||
~run=(inputs, _, env, reducer) =>
|
~run=(inputs, env, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(array), initialValue, IEvLambda(lambda)] =>
|
| [IEvArray(array), initialValue, IEvLambda(lambda)] =>
|
||||||
Ok(Internals.reduceReverse(array, initialValue, lambda, env, reducer))
|
Ok(Internals.reduceReverse(array, initialValue, lambda, env, reducer))
|
||||||
|
@ -244,7 +244,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="filter",
|
~name="filter",
|
||||||
~inputs=[FRTypeArray(FRTypeAny), FRTypeLambda],
|
~inputs=[FRTypeArray(FRTypeAny), FRTypeLambda],
|
||||||
~run=(inputs, _, env, reducer) =>
|
~run=(inputs, env, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(array), IEvLambda(lambda)] =>
|
| [IEvArray(array), IEvLambda(lambda)] =>
|
||||||
Ok(Internals.filter(array, lambda, env, reducer))
|
Ok(Internals.filter(array, lambda, env, reducer))
|
||||||
|
|
|
@ -9,7 +9,7 @@ module ArrayNumberDist = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeArray(FRTypeNumber)],
|
~inputs=[FRTypeArray(FRTypeNumber)],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
inputs
|
inputs
|
||||||
->Prepare.ToTypedArray.numbers
|
->Prepare.ToTypedArray.numbers
|
||||||
->E.R.bind(r => E.A.length(r) === 0 ? Error("List is empty") : Ok(r))
|
->E.R.bind(r => E.A.length(r) === 0 ? Error("List is empty") : Ok(r))
|
||||||
|
|
|
@ -60,7 +60,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="fromDist",
|
~name="fromDist",
|
||||||
~inputs=[FRTypeDist],
|
~inputs=[FRTypeDist],
|
||||||
~run=(inputs, _, env, _) =>
|
~run=(inputs, env, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvDistribution(dist)] =>
|
| [IEvDistribution(dist)] =>
|
||||||
GenericDist.toPointSet(
|
GenericDist.toPointSet(
|
||||||
|
@ -89,7 +89,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="mapY",
|
~name="mapY",
|
||||||
~inputs=[FRTypeDist, FRTypeLambda],
|
~inputs=[FRTypeDist, FRTypeLambda],
|
||||||
~run=(inputs, _, env, reducer) =>
|
~run=(inputs, env, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvDistribution(PointSet(dist)), IEvLambda(lambda)] =>
|
| [IEvDistribution(PointSet(dist)), IEvLambda(lambda)] =>
|
||||||
Internal.mapY(dist, lambda, env, reducer)
|
Internal.mapY(dist, lambda, env, reducer)
|
||||||
|
@ -117,7 +117,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="makeContinuous",
|
~name="makeContinuous",
|
||||||
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
inputsToDist(inputs, r => Continuous(Continuous.make(r)))->E.R2.errMap(wrapError),
|
inputsToDist(inputs, r => Continuous(Continuous.make(r)))->E.R2.errMap(wrapError),
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
|
@ -141,7 +141,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="makeDiscrete",
|
~name="makeDiscrete",
|
||||||
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
inputsToDist(inputs, r => Discrete(Discrete.make(r)))->E.R2.errMap(wrapError),
|
inputsToDist(inputs, r => Discrete(Discrete.make(r)))->E.R2.errMap(wrapError),
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
|
|
|
@ -89,7 +89,7 @@ let libaryBase = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="fromDist",
|
~name="fromDist",
|
||||||
~inputs=[FRTypeDist],
|
~inputs=[FRTypeDist],
|
||||||
~run=(inputs, _, environment, _) =>
|
~run=(inputs, environment, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvDistribution(dist)] =>
|
| [IEvDistribution(dist)] =>
|
||||||
GenericDist.toSampleSetDist(dist, environment.sampleCount)
|
GenericDist.toSampleSetDist(dist, environment.sampleCount)
|
||||||
|
@ -113,7 +113,7 @@ let libaryBase = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="fromList",
|
~name="fromList",
|
||||||
~inputs=[FRTypeArray(FRTypeNumber)],
|
~inputs=[FRTypeArray(FRTypeNumber)],
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
let sampleSet =
|
let sampleSet =
|
||||||
inputs->Prepare.ToTypedArray.numbers |> E.R2.bind(r =>
|
inputs->Prepare.ToTypedArray.numbers |> E.R2.bind(r =>
|
||||||
SampleSetDist.make(r)->E.R2.errMap(_ => "AM I HERE? WHYERE AMI??")
|
SampleSetDist.make(r)->E.R2.errMap(_ => "AM I HERE? WHYERE AMI??")
|
||||||
|
@ -138,7 +138,7 @@ let libaryBase = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="toList",
|
~name="toList",
|
||||||
~inputs=[FRTypeDist],
|
~inputs=[FRTypeDist],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvDistribution(SampleSet(dist))] =>
|
| [IEvDistribution(SampleSet(dist))] =>
|
||||||
dist->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok
|
dist->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok
|
||||||
|
@ -159,7 +159,7 @@ let libaryBase = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="fromFn",
|
~name="fromFn",
|
||||||
~inputs=[FRTypeLambda],
|
~inputs=[FRTypeLambda],
|
||||||
~run=(inputs, _, environment, reducer) =>
|
~run=(inputs, environment, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvLambda(lambda)] =>
|
| [IEvLambda(lambda)] =>
|
||||||
switch Internal.fromFn(lambda, environment, reducer) {
|
switch Internal.fromFn(lambda, environment, reducer) {
|
||||||
|
@ -183,7 +183,7 @@ let libaryBase = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="map",
|
~name="map",
|
||||||
~inputs=[FRTypeDist, FRTypeLambda],
|
~inputs=[FRTypeDist, FRTypeLambda],
|
||||||
~run=(inputs, _, environment, reducer) =>
|
~run=(inputs, environment, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvDistribution(SampleSet(dist)), IEvLambda(lambda)] =>
|
| [IEvDistribution(SampleSet(dist)), IEvLambda(lambda)] =>
|
||||||
Internal.map1(dist, lambda, environment, reducer)
|
Internal.map1(dist, lambda, environment, reducer)
|
||||||
|
@ -206,7 +206,7 @@ let libaryBase = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="map2",
|
~name="map2",
|
||||||
~inputs=[FRTypeDist, FRTypeDist, FRTypeLambda],
|
~inputs=[FRTypeDist, FRTypeDist, FRTypeLambda],
|
||||||
~run=(inputs, _, environment, reducer) => {
|
~run=(inputs, environment, reducer) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [
|
| [
|
||||||
IEvDistribution(SampleSet(dist1)),
|
IEvDistribution(SampleSet(dist1)),
|
||||||
|
@ -234,7 +234,7 @@ let libaryBase = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="map3",
|
~name="map3",
|
||||||
~inputs=[FRTypeDist, FRTypeDist, FRTypeDist, FRTypeLambda],
|
~inputs=[FRTypeDist, FRTypeDist, FRTypeDist, FRTypeLambda],
|
||||||
~run=(inputs, _, environment, reducer) =>
|
~run=(inputs, environment, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [
|
| [
|
||||||
IEvDistribution(SampleSet(dist1)),
|
IEvDistribution(SampleSet(dist1)),
|
||||||
|
@ -262,7 +262,7 @@ let libaryBase = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="mapN",
|
~name="mapN",
|
||||||
~inputs=[FRTypeArray(FRTypeDist), FRTypeLambda],
|
~inputs=[FRTypeArray(FRTypeDist), FRTypeLambda],
|
||||||
~run=(inputs, _, environment, reducer) =>
|
~run=(inputs, environment, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(dists), IEvLambda(lambda)] =>
|
| [IEvArray(dists), IEvLambda(lambda)] =>
|
||||||
Internal.mapN(dists, lambda, environment, reducer)
|
Internal.mapN(dists, lambda, environment, reducer)
|
||||||
|
@ -280,7 +280,7 @@ module Comparison = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs,
|
~inputs,
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
run(inputs)
|
run(inputs)
|
||||||
},
|
},
|
||||||
(),
|
(),
|
||||||
|
|
|
@ -30,7 +30,7 @@ let library = [
|
||||||
("prior", FRTypeDist),
|
("prior", FRTypeDist),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
~run=(inputs, _, environment, _) => {
|
~run=(inputs, environment, _) => {
|
||||||
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.threeArgs(inputs, ("estimate", "answer", "prior")) {
|
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.threeArgs(inputs, ("estimate", "answer", "prior")) {
|
||||||
| Ok([IEvDistribution(estimate), IEvDistribution(d), IEvDistribution(prior)]) =>
|
| Ok([IEvDistribution(estimate), IEvDistribution(d), IEvDistribution(prior)]) =>
|
||||||
runScoring(estimate, Score_Dist(d), Some(prior), environment)
|
runScoring(estimate, Score_Dist(d), Some(prior), environment)
|
||||||
|
@ -49,7 +49,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="logScore",
|
~name="logScore",
|
||||||
~inputs=[FRTypeRecord([("estimate", FRTypeDist), ("answer", FRTypeDistOrNumber)])],
|
~inputs=[FRTypeRecord([("estimate", FRTypeDist), ("answer", FRTypeDistOrNumber)])],
|
||||||
~run=(inputs, _, environment, _) => {
|
~run=(inputs, environment, _) => {
|
||||||
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs(inputs, ("estimate", "answer")) {
|
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs(inputs, ("estimate", "answer")) {
|
||||||
| Ok([IEvDistribution(estimate), IEvDistribution(d)]) =>
|
| Ok([IEvDistribution(estimate), IEvDistribution(d)]) =>
|
||||||
runScoring(estimate, Score_Dist(d), None, environment)
|
runScoring(estimate, Score_Dist(d), None, environment)
|
||||||
|
@ -74,7 +74,7 @@ let library = [
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="klDivergence",
|
~name="klDivergence",
|
||||||
~inputs=[FRTypeDist, FRTypeDist],
|
~inputs=[FRTypeDist, FRTypeDist],
|
||||||
~run=(inputs, _, environment, _) => {
|
~run=(inputs, environment, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvDistribution(estimate), IEvDistribution(d)] =>
|
| [IEvDistribution(estimate), IEvDistribution(d)] =>
|
||||||
runScoring(estimate, Score_Dist(d), None, environment)
|
runScoring(estimate, Score_Dist(d), None, environment)
|
||||||
|
|
|
@ -9,7 +9,7 @@ let makeUnitFn = (name: string, multiplier: float) => {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="fromUnit_" ++ name,
|
~name="fromUnit_" ++ name,
|
||||||
~inputs=[FRTypeNumber],
|
~inputs=[FRTypeNumber],
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvNumber(f)] => IEvNumber(f *. multiplier)->Ok
|
| [IEvNumber(f)] => IEvNumber(f *. multiplier)->Ok
|
||||||
| _ => FunctionRegistry_Helpers.impossibleError->Error
|
| _ => FunctionRegistry_Helpers.impossibleError->Error
|
||||||
|
|
|
@ -30,7 +30,6 @@ type fnDefinition = {
|
||||||
inputs: array<frType>,
|
inputs: array<frType>,
|
||||||
run: (
|
run: (
|
||||||
array<Reducer_T.value>,
|
array<Reducer_T.value>,
|
||||||
unit,
|
|
||||||
Reducer_T.environment,
|
Reducer_T.environment,
|
||||||
Reducer_T.reducerFn,
|
Reducer_T.reducerFn,
|
||||||
) => result<Reducer_T.value, errorValue>,
|
) => result<Reducer_T.value, errorValue>,
|
||||||
|
@ -130,7 +129,7 @@ module FnDefinition = {
|
||||||
reducer: Reducer_T.reducerFn,
|
reducer: Reducer_T.reducerFn,
|
||||||
) => {
|
) => {
|
||||||
switch t->isMatch(args) {
|
switch t->isMatch(args) {
|
||||||
| true => t.run(args, (), env, reducer)
|
| true => t.run(args, env, reducer)
|
||||||
| false => REOther("Incorrect Types")->Error
|
| false => REOther("Incorrect Types")->Error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,7 +220,7 @@ module DefineFn = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeNumber],
|
~inputs=[FRTypeNumber],
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvNumber(x)] => fn(x)->IEvNumber->Ok
|
| [IEvNumber(x)] => fn(x)->IEvNumber->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -232,7 +232,7 @@ module DefineFn = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeNumber, FRTypeNumber],
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvNumber->Ok
|
| [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvNumber->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -244,7 +244,7 @@ module DefineFn = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeNumber, FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeNumber, FRTypeNumber, FRTypeNumber],
|
||||||
~run=(inputs, _, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvNumber(x), IEvNumber(y), IEvNumber(z)] => fn(x, y, z)->IEvNumber->Ok
|
| [IEvNumber(x), IEvNumber(y), IEvNumber(z)] => fn(x, y, z)->IEvNumber->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -292,7 +292,7 @@ module Make = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeNumber],
|
~inputs=[FRTypeNumber],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvNumber(x)] => fn(x)->IEvNumber->Ok
|
| [IEvNumber(x)] => fn(x)->IEvNumber->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -322,7 +322,7 @@ module Make = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeNumber, FRTypeNumber],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvNumber->Ok
|
| [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvNumber->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -352,7 +352,7 @@ module Make = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeNumber, FRTypeNumber],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvBool->Ok
|
| [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvBool->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
@ -382,7 +382,7 @@ module Make = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeBool, FRTypeBool],
|
~inputs=[FRTypeBool, FRTypeBool],
|
||||||
~run=(inputs, _, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvBool(x), IEvBool(y)] => fn(x, y)->IEvBool->Ok
|
| [IEvBool(x), IEvBool(y)] => fn(x, y)->IEvBool->Ok
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user