Simple experiment of it working
This commit is contained in:
parent
b67c90eb06
commit
88ae0e25b4
|
@ -95,9 +95,13 @@ module FnDefinition = {
|
||||||
if E.A.length(f.inputs) !== E.A.length(args) {
|
if E.A.length(f.inputs) !== E.A.length(args) {
|
||||||
None
|
None
|
||||||
} else {
|
} 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.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<expressionValue>) => {
|
let run = (f: fnDefinition, args: array<expressionValue>) => {
|
||||||
|
Js.log3("Run", f, args)
|
||||||
let argValues = getArgValues(f, args)
|
let argValues = getArgValues(f, args)
|
||||||
|
Js.log2("RunArgValues", argValues)
|
||||||
switch argValues {
|
switch argValues {
|
||||||
| Some(values) => f.run(values)
|
| Some(values) => f.run(values)
|
||||||
| None => Error("Impossible")
|
| None => Error("Impossible")
|
||||||
|
@ -227,17 +233,21 @@ module Registry = {
|
||||||
|
|
||||||
let matchAndRun = (r: registry, fnName: string, args: array<expressionValue>) => {
|
let matchAndRun = (r: registry, fnName: string, args: array<expressionValue>) => {
|
||||||
switch findMatches(r, fnName, args) {
|
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
|
| _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let twoNumberInputs = (inputs: array<value>) =>
|
let twoNumberInputs = (inputs: array<value>) =>{
|
||||||
|
Js.log2("HII",inputs);
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [Number(n1), Number(n2)] => Ok(n1, n2)
|
| [Number(n1), Number(n2)] => Ok(n1, n2)
|
||||||
| _ => Error("Wrong inputs / Logically impossible")
|
| _ => Error("Wrong inputs / Logically impossible")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let twoNumberInputsRecord = (v1, v2, inputs: array<value>) =>
|
let twoNumberInputsRecord = (v1, v2, inputs: array<value>) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
|
@ -270,7 +280,7 @@ let normal = Function.make(
|
||||||
),
|
),
|
||||||
Function.makeDefinition("normal", [I_Record([("p5", I_Numeric), ("p95", I_Numeric)])], inputs =>
|
Function.makeDefinition("normal", [I_Record([("p5", I_Numeric), ("p95", I_Numeric)])], inputs =>
|
||||||
twoNumberInputsRecord("p5", "p95", inputs)->E.R.bind(((mean, stdev)) =>
|
twoNumberInputsRecord("p5", "p95", inputs)->E.R.bind(((mean, stdev)) =>
|
||||||
meanStdev(mean, stdev)
|
Ok(p5and95(mean, stdev))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -227,8 +227,8 @@ let dispatchToGenericOutput = (
|
||||||
| ("delta", [EvNumber(f)]) =>
|
| ("delta", [EvNumber(f)]) =>
|
||||||
SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput
|
SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput
|
||||||
| (
|
| (
|
||||||
("normal"
|
(
|
||||||
| "uniform"
|
"uniform"
|
||||||
| "beta"
|
| "beta"
|
||||||
| "lognormal"
|
| "lognormal"
|
||||||
| "cauchy"
|
| "cauchy"
|
||||||
|
@ -386,6 +386,19 @@ let genericOutputToReducerValue = (o: DistributionOperation.outputType): result<
|
||||||
| GenDistError(err) => Error(REDistributionError(err))
|
| GenDistError(err) => Error(REDistributionError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
let dispatch = (call, environment) => {
|
let registered = [FunctionRegistry.normal]
|
||||||
dispatchToGenericOutput(call, environment)->E.O2.fmap(genericOutputToReducerValue)
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -646,6 +646,14 @@ module A = {
|
||||||
O.flatten(getByOpen(r, l => l(), O.isSome))
|
O.flatten(getByOpen(r, l => l(), O.isSome))
|
||||||
|
|
||||||
let firstSomeFnWithDefault = (r, default) => firstSomeFn(r)->O2.default(default)
|
let firstSomeFnWithDefault = (r, default) => firstSomeFn(r)->O2.default(default)
|
||||||
|
|
||||||
|
let openIfAllSome = (optionals: array<option<'a>>): option<array<'a>> => {
|
||||||
|
if all(O.isSome, optionals) {
|
||||||
|
Some(optionals |> fmap(O.toExn("Warning: This should not have happened")))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module R = {
|
module R = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user