diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry.res b/packages/squiggle-lang/src/rescript/FunctionRegistry.res index 4cd20e87..f0d142c1 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry.res @@ -95,9 +95,13 @@ module FnDefinition = { if E.A.length(f.inputs) !== E.A.length(args) { None } else { - E.A.zip(inputTypes, args) + let foo = E.A.zip(inputTypes, args) + ->(e => {Js.log2("Here", e); e}) ->E.A2.fmap(((input, arg)) => matchInput(input, arg)) - ->E.A.O.arrSomeToSomeArr + ->(e => {Js.log2("Here2", e); e}) + ->E.A.O.openIfAllSome + ->(e => {Js.log2("Here3", e); e}); + foo } } @@ -117,7 +121,9 @@ module FnDefinition = { } let run = (f: fnDefinition, args: array) => { + Js.log3("Run", f, args) let argValues = getArgValues(f, args) + Js.log2("RunArgValues", argValues) switch argValues { | Some(values) => f.run(values) | None => Error("Impossible") @@ -227,17 +233,21 @@ module Registry = { let matchAndRun = (r: registry, fnName: string, args: array) => { switch findMatches(r, fnName, args) { - | Match.FullMatch(m) => fullMatchToDef(r, m)->E.O2.fmap(FnDefinition.run(_, args)) + | Match.FullMatch(m) => fullMatchToDef(r, m)->E.O2.fmap(r => { + FnDefinition.run(r, args) + }) | _ => None } } } -let twoNumberInputs = (inputs: array) => +let twoNumberInputs = (inputs: array) =>{ + Js.log2("HII",inputs); switch inputs { | [Number(n1), Number(n2)] => Ok(n1, n2) | _ => Error("Wrong inputs / Logically impossible") } +} let twoNumberInputsRecord = (v1, v2, inputs: array) => switch inputs { @@ -270,7 +280,7 @@ let normal = Function.make( ), Function.makeDefinition("normal", [I_Record([("p5", I_Numeric), ("p95", I_Numeric)])], inputs => twoNumberInputsRecord("p5", "p95", inputs)->E.R.bind(((mean, stdev)) => - meanStdev(mean, stdev) + Ok(p5and95(mean, stdev)) ) ), ], diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res index 0f29f9db..824b5b32 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res @@ -227,8 +227,8 @@ let dispatchToGenericOutput = ( | ("delta", [EvNumber(f)]) => SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput | ( - ("normal" - | "uniform" + ( + "uniform" | "beta" | "lognormal" | "cauchy" @@ -386,6 +386,19 @@ let genericOutputToReducerValue = (o: DistributionOperation.outputType): result< | GenDistError(err) => Error(REDistributionError(err)) } -let dispatch = (call, environment) => { - dispatchToGenericOutput(call, environment)->E.O2.fmap(genericOutputToReducerValue) +let registered = [FunctionRegistry.normal] + +let tryRegistry = (call:ExpressionValue.functionCall) => { + let (fnName, args) = call; + let response = FunctionRegistry.Registry.matchAndRun(registered, fnName, args) + let foo = response -> E.O2.fmap(r => r->E.R2.errMap(s => Reducer_ErrorValue.RETodo(s))) + foo +} + +let dispatch = (call:ExpressionValue.functionCall, environment) => { + let regularDispatch = dispatchToGenericOutput(call, environment)->E.O2.fmap(genericOutputToReducerValue) + switch(regularDispatch){ + | Some(x) => Some(x) + | None => tryRegistry(call) + } } diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index 06d8d4e9..b096303d 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -646,6 +646,14 @@ module A = { O.flatten(getByOpen(r, l => l(), O.isSome)) let firstSomeFnWithDefault = (r, default) => firstSomeFn(r)->O2.default(default) + + let openIfAllSome = (optionals: array>): option> => { + if all(O.isSome, optionals) { + Some(optionals |> fmap(O.toExn("Warning: This should not have happened"))) + } else { + None + } + } } module R = {