Minor cleanup
This commit is contained in:
parent
6248818531
commit
31e6f13472
|
@ -8,7 +8,7 @@ type rec frType =
|
|||
| FRTypeNumber
|
||||
| FRTypeNumeric
|
||||
| FRTypeDistOrNumber
|
||||
| FRTLambda
|
||||
| FRTypeLambda
|
||||
| FRTypeRecord(frTypeRecord)
|
||||
| FRTypeArray(frType)
|
||||
| FRTypeOption(frType)
|
||||
|
@ -61,7 +61,9 @@ module FRType = {
|
|||
}
|
||||
| FRTypeArray(r) => `record(${toString(r)})`
|
||||
| FRTypeOption(v) => `option(${toString(v)})`
|
||||
| FRTLambda => `lambda`
|
||||
| FRTypeLambda => `lambda`
|
||||
| FRTypeString => `string`
|
||||
| FRTypeVariant(_) => "variant"
|
||||
}
|
||||
|
||||
let rec matchWithExpressionValue = (t: t, r: expressionValue): option<frValue> =>
|
||||
|
@ -74,7 +76,11 @@ module FRType = {
|
|||
| (FRTypeNumeric, EvNumber(f)) => Some(FRValueNumber(f))
|
||||
| (FRTypeNumeric, EvDistribution(Symbolic(#Float(f)))) => Some(FRValueNumber(f))
|
||||
| (FRTypeOption(v), _) => Some(FRValueOption(matchWithExpressionValue(v, r)))
|
||||
| (FRTLambda, EvLambda(f)) => Some(FRValueLambda(f))
|
||||
| (FRTypeLambda, EvLambda(f)) => Some(FRValueLambda(f))
|
||||
| (FRTypeArray(intendedType), EvArray(elements)) => {
|
||||
let el = elements->E.A2.fmap(matchWithExpressionValue(intendedType))
|
||||
E.A.O.openIfAllSome(el)->E.O2.fmap(r => FRValueArray(r))
|
||||
}
|
||||
| (FRTypeRecord(recordParams), EvRecord(record)) => {
|
||||
let getAndMatch = (name, input) =>
|
||||
E.Dict.get(record, name)->E.O.bind(matchWithExpressionValue(input))
|
||||
|
|
|
@ -19,6 +19,12 @@ module Prepare = {
|
|||
| [FRValueRecord([(_, n1), (_, n2)])] => Ok([n1, n2])
|
||||
| _ => Error(impossibleError)
|
||||
}
|
||||
|
||||
let toArgs = (inputs: ts): result<ts, err> =>
|
||||
switch inputs {
|
||||
| [FRValueRecord(args)] => args->E.A2.fmap(((_, b)) => b)->Ok
|
||||
| _ => Error(impossibleError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,25 +3,55 @@ open FunctionRegistry_Helpers
|
|||
|
||||
let twoArgs = E.Tuple2.toFnCall
|
||||
|
||||
// ~run=(inputs, env) => switch(inputs->FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs){
|
||||
// | (FRTypeArray(records), FRValueLambdaValue(fn)) => {
|
||||
// records->E.A.fmap2(r => r->FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs->FunctionRegistry_Helpers.Prepare)
|
||||
// })
|
||||
// }
|
||||
// let variant = FRTypeVariant(["Numeric", "Date"])
|
||||
let recordType = FRTypeRecord([("min", FRTypeNumber), ("max", FRTypeNumber)])
|
||||
module FnDeclaration = {
|
||||
type range = {min: float, max: float}
|
||||
let makeRange = (min, max) => {min: min, max: max}
|
||||
type t = {
|
||||
fn: ReducerInterface_ExpressionValue.lambdaValue,
|
||||
args: array<range>,
|
||||
}
|
||||
|
||||
let validate = (def: t) => {
|
||||
let {parameters, _} = def.fn
|
||||
E.A.length(parameters) == E.A.length(def.args)
|
||||
}
|
||||
|
||||
let frType = FRTypeRecord([
|
||||
("fn", FRTypeLambda),
|
||||
("inputs", FRTypeArray(FRTypeRecord([("min", FRTypeNumber), ("max", FRTypeNumber)]))),
|
||||
])
|
||||
|
||||
let fromExpressionValue = (e: expressionValue) => {
|
||||
let values = FunctionRegistry_Core.FRType.matchWithExpressionValue(frType, e)
|
||||
switch values->E.O2.fmap(r =>
|
||||
FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs([r])
|
||||
) {
|
||||
| Some(Ok([FRValueLambda(lambda), FRValueArray(inputs)])) => {
|
||||
open FunctionRegistry_Helpers.Prepare
|
||||
let getMinMax = arg =>
|
||||
ToValueArray.Record.toArgs([arg])
|
||||
->E.R.bind(ToValueTuple.twoNumbers)
|
||||
->E.R2.fmap(((min, max)) => makeRange(min, max))
|
||||
inputs
|
||||
->E.A2.fmap(getMinMax)
|
||||
->E.A.R.firstErrorOrOpen
|
||||
->E.R2.fmap(args => {fn: lambda, args: args})
|
||||
}
|
||||
| _ => Error("Error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let registry = [
|
||||
Function.make(
|
||||
~name="FnMake",
|
||||
~definitions=[
|
||||
FnDefinition.make(
|
||||
~name="declareFn",
|
||||
~inputs=[FRTypeRecord([("inputs", FRTypeArray(recordType))])],
|
||||
~run=(inputs, _) => {
|
||||
let foo = FunctionRegistry_Core.FRType.matchReverse(inputs->E.A.unsafe_get(0))
|
||||
foo->Ok
|
||||
}
|
||||
),
|
||||
FnDefinition.make(~name="declareFn", ~inputs=[FnDeclaration.frType], ~run=(inputs, _) => {
|
||||
let result = inputs->E.A.unsafe_get(0)->FunctionRegistry_Core.FRType.matchReverse->Ok
|
||||
let foo = result->E.R2.fmap(FnDeclaration.fromExpressionValue)
|
||||
Js.log2("HIHIHI", foo)
|
||||
result
|
||||
}),
|
||||
],
|
||||
),
|
||||
Function.make(
|
||||
|
|
Loading…
Reference in New Issue
Block a user