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

View File

@ -3,57 +3,47 @@ open FunctionRegistry_Helpers
let twoArgs = E.Tuple2.toFnCall let twoArgs = E.Tuple2.toFnCall
module NormalFn = { let registry = [
let fnName = "normal" Function.make(
let toFn = Function.make(
~name="Normal", ~name="Normal",
~definitions=[ ~definitions=[
TwoArgDist.mkRegular(fnName, twoArgs(SymbolicDist.Normal.make)), TwoArgDist.make("normal", twoArgs(SymbolicDist.Normal.make)),
TwoArgDist.mkDef90th(fnName, r => twoArgs(SymbolicDist.Normal.from90PercentCI, r)->Ok), TwoArgDist.makeRecordP5P95("normal", r => twoArgs(SymbolicDist.Normal.from90PercentCI, r)->Ok),
TwoArgDist.mkDefMeanStdev(fnName, twoArgs(SymbolicDist.Normal.make)), TwoArgDist.makeRecordMeanStdev("normal", twoArgs(SymbolicDist.Normal.make)),
], ],
) ),
} Function.make(
module LognormalFn = {
let fnName = "lognormal"
let toFn = Function.make(
~name="Lognormal", ~name="Lognormal",
~definitions=[ ~definitions=[
TwoArgDist.mkRegular(fnName, twoArgs(SymbolicDist.Lognormal.make)), TwoArgDist.make("lognormal", twoArgs(SymbolicDist.Lognormal.make)),
TwoArgDist.mkDef90th(fnName, r => twoArgs(SymbolicDist.Lognormal.from90PercentCI, r)->Ok), TwoArgDist.makeRecordP5P95("lognormal", r =>
TwoArgDist.mkDefMeanStdev(fnName, twoArgs(SymbolicDist.Lognormal.fromMeanAndStdev)), twoArgs(SymbolicDist.Lognormal.from90PercentCI, r)->Ok
),
TwoArgDist.makeRecordMeanStdev("lognormal", twoArgs(SymbolicDist.Lognormal.fromMeanAndStdev)),
], ],
) ),
}
let more = [
Function.make( Function.make(
~name="Uniform", ~name="Uniform",
~definitions=[TwoArgDist.mkRegular("uniform", twoArgs(SymbolicDist.Uniform.make))], ~definitions=[TwoArgDist.make("uniform", twoArgs(SymbolicDist.Uniform.make))],
), ),
Function.make( Function.make(
~name="Beta", ~name="Beta",
~definitions=[TwoArgDist.mkRegular("beta", twoArgs(SymbolicDist.Beta.make))], ~definitions=[TwoArgDist.make("beta", twoArgs(SymbolicDist.Beta.make))],
), ),
Function.make( Function.make(
~name="Cauchy", ~name="Cauchy",
~definitions=[TwoArgDist.mkRegular("cauchy", twoArgs(SymbolicDist.Cauchy.make))], ~definitions=[TwoArgDist.make("cauchy", twoArgs(SymbolicDist.Cauchy.make))],
), ),
Function.make( Function.make(
~name="Gamma", ~name="Gamma",
~definitions=[TwoArgDist.mkRegular("gamma", twoArgs(SymbolicDist.Gamma.make))], ~definitions=[TwoArgDist.make("gamma", twoArgs(SymbolicDist.Gamma.make))],
), ),
Function.make( Function.make(
~name="Logistic", ~name="Logistic",
~definitions=[TwoArgDist.mkRegular("logistic", twoArgs(SymbolicDist.Logistic.make))], ~definitions=[TwoArgDist.make("logistic", twoArgs(SymbolicDist.Logistic.make))],
), ),
Function.make( Function.make(
~name="To", ~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)) | 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) => { let tryRegistry = ((fnName, args): ExpressionValue.functionCall, env) => {
FunctionRegistry_Core.Registry.matchAndRun(~registry, ~fnName, ~args, ~env)->E.O2.fmap( FunctionRegistry_Core.Registry.matchAndRun(~registry, ~fnName, ~args, ~env)->E.O2.fmap(