Minor cleanup

This commit is contained in:
Ozzie Gooen 2022-05-22 10:38:17 -04:00
parent c200259c79
commit ee94a054d0
3 changed files with 24 additions and 33 deletions

View File

@ -96,13 +96,13 @@ module TwoArgDist = {
->E.R.bind(Process.twoDistsOrNumbersToDistUsingSymbolicDist(~fn, ~values=_, ~env))
->E.R2.fmap(Wrappers.evDistribution)
let mkRegular = (name, fn) => {
let make = (name, fn) => {
FnDefinition.make(~name, ~inputs=[FRTypeDistOrNumber, FRTypeDistOrNumber], ~run=(inputs, env) =>
inputs->Prepare.ToValueTuple.twoDistOrNumber->process(~fn, ~env)
)
}
let mkDef90th = (name, fn) => {
let makeRecordP5P95 = (name, fn) => {
FnDefinition.make(
~name,
~inputs=[FRTypeRecord([("p5", FRTypeDistOrNumber), ("p95", FRTypeDistOrNumber)])],
@ -110,7 +110,7 @@ module TwoArgDist = {
)
}
let mkDefMeanStdev = (name, fn) => {
let makeRecordMeanStdev = (name, fn) => {
FnDefinition.make(
~name,
~inputs=[FRTypeRecord([("mean", FRTypeDistOrNumber), ("stdev", FRTypeDistOrNumber)])],

View File

@ -3,57 +3,47 @@ open FunctionRegistry_Helpers
let twoArgs = E.Tuple2.toFnCall
module NormalFn = {
let fnName = "normal"
let toFn = Function.make(
let registry = [
Function.make(
~name="Normal",
~definitions=[
TwoArgDist.mkRegular(fnName, twoArgs(SymbolicDist.Normal.make)),
TwoArgDist.mkDef90th(fnName, r => twoArgs(SymbolicDist.Normal.from90PercentCI, r)->Ok),
TwoArgDist.mkDefMeanStdev(fnName, twoArgs(SymbolicDist.Normal.make)),
TwoArgDist.make("normal", twoArgs(SymbolicDist.Normal.make)),
TwoArgDist.makeRecordP5P95("normal", r => twoArgs(SymbolicDist.Normal.from90PercentCI, r)->Ok),
TwoArgDist.makeRecordMeanStdev("normal", twoArgs(SymbolicDist.Normal.make)),
],
)
}
module LognormalFn = {
let fnName = "lognormal"
let toFn = Function.make(
),
Function.make(
~name="Lognormal",
~definitions=[
TwoArgDist.mkRegular(fnName, twoArgs(SymbolicDist.Lognormal.make)),
TwoArgDist.mkDef90th(fnName, r => twoArgs(SymbolicDist.Lognormal.from90PercentCI, r)->Ok),
TwoArgDist.mkDefMeanStdev(fnName, twoArgs(SymbolicDist.Lognormal.fromMeanAndStdev)),
TwoArgDist.make("lognormal", twoArgs(SymbolicDist.Lognormal.make)),
TwoArgDist.makeRecordP5P95("lognormal", r =>
twoArgs(SymbolicDist.Lognormal.from90PercentCI, r)->Ok
),
TwoArgDist.makeRecordMeanStdev("lognormal", twoArgs(SymbolicDist.Lognormal.fromMeanAndStdev)),
],
)
}
let more = [
),
Function.make(
~name="Uniform",
~definitions=[TwoArgDist.mkRegular("uniform", twoArgs(SymbolicDist.Uniform.make))],
~definitions=[TwoArgDist.make("uniform", twoArgs(SymbolicDist.Uniform.make))],
),
Function.make(
~name="Beta",
~definitions=[TwoArgDist.mkRegular("beta", twoArgs(SymbolicDist.Beta.make))],
~definitions=[TwoArgDist.make("beta", twoArgs(SymbolicDist.Beta.make))],
),
Function.make(
~name="Cauchy",
~definitions=[TwoArgDist.mkRegular("cauchy", twoArgs(SymbolicDist.Cauchy.make))],
~definitions=[TwoArgDist.make("cauchy", twoArgs(SymbolicDist.Cauchy.make))],
),
Function.make(
~name="Gamma",
~definitions=[TwoArgDist.mkRegular("gamma", twoArgs(SymbolicDist.Gamma.make))],
~definitions=[TwoArgDist.make("gamma", twoArgs(SymbolicDist.Gamma.make))],
),
Function.make(
~name="Logistic",
~definitions=[TwoArgDist.mkRegular("logistic", twoArgs(SymbolicDist.Logistic.make))],
~definitions=[TwoArgDist.make("logistic", twoArgs(SymbolicDist.Logistic.make))],
),
Function.make(
~name="To",
~definitions=[TwoArgDist.mkRegular("to", twoArgs(SymbolicDist.From90thPercentile.make))],
~definitions=[TwoArgDist.make("to", twoArgs(SymbolicDist.From90thPercentile.make))],
),
]
let allFunctions = E.A.append([NormalFn.toFn, LognormalFn.toFn], more)

View File

@ -361,7 +361,8 @@ let genericOutputToReducerValue = (o: DistributionOperation.outputType): result<
| GenDistError(err) => Error(REDistributionError(err))
}
let registry = FunctionRegistry_Library.allFunctions
// I expect that it's important to build this first, so it doesn't get recalculated for each tryRegistry() call.
let registry = FunctionRegistry_Library.registry
let tryRegistry = ((fnName, args): ExpressionValue.functionCall, env) => {
FunctionRegistry_Core.Registry.matchAndRun(~registry, ~fnName, ~args, ~env)->E.O2.fmap(