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