Merge pull request #483 from quantified-uncertainty/reducer-dev
Reducer: Foreign Function Interface
This commit is contained in:
commit
29a2ba4e21
|
@ -9,3 +9,8 @@ describe("map reduce", () => {
|
||||||
testEvalToBe("arr=[1,2,3]; reverse(arr)", "Ok([3,2,1])")
|
testEvalToBe("arr=[1,2,3]; reverse(arr)", "Ok([3,2,1])")
|
||||||
testEvalToBe("check(x)=(x==2);arr=[1,2,3]; keep(arr,check)", "Ok([2])")
|
testEvalToBe("check(x)=(x==2);arr=[1,2,3]; keep(arr,check)", "Ok([2])")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Skip.describe("map reduce (sam)", () => {
|
||||||
|
testEvalToBe("addone(x)=x+1; map(2, addone)", "Error???")
|
||||||
|
testEvalToBe("addone(x)=x+1; map(2, {x: addone})", "Error???")
|
||||||
|
})
|
||||||
|
|
|
@ -1,11 +1,27 @@
|
||||||
module ErrorValue = Reducer_ErrorValue
|
module ErrorValue = Reducer_ErrorValue
|
||||||
module Expression = Reducer_Expression
|
module Expression = Reducer_Expression
|
||||||
|
module ExpressionValue = ReducerInterface_ExpressionValue
|
||||||
|
module Lambda = Reducer_Expression_Lambda
|
||||||
|
|
||||||
type environment = ReducerInterface_ExpressionValue.environment
|
type environment = ReducerInterface_ExpressionValue.environment
|
||||||
type errorValue = Reducer_ErrorValue.errorValue
|
type errorValue = Reducer_ErrorValue.errorValue
|
||||||
type expressionValue = ReducerInterface_ExpressionValue.expressionValue
|
type expressionValue = ReducerInterface_ExpressionValue.expressionValue
|
||||||
type externalBindings = ReducerInterface_ExpressionValue.externalBindings
|
type externalBindings = ReducerInterface_ExpressionValue.externalBindings
|
||||||
|
type lambdaValue = ExpressionValue.lambdaValue
|
||||||
|
|
||||||
let evaluate = Expression.evaluate
|
let evaluate = Expression.evaluate
|
||||||
let evaluateUsingOptions = Expression.evaluateUsingOptions
|
let evaluateUsingOptions = Expression.evaluateUsingOptions
|
||||||
let evaluatePartialUsingExternalBindings = Expression.evaluatePartialUsingExternalBindings
|
let evaluatePartialUsingExternalBindings = Expression.evaluatePartialUsingExternalBindings
|
||||||
let parse = Expression.parse
|
let parse = Expression.parse
|
||||||
|
|
||||||
|
let foreignFunctionInterface = (
|
||||||
|
lambdaValue: lambdaValue,
|
||||||
|
argArray: array<expressionValue>,
|
||||||
|
environment: ExpressionValue.environment,
|
||||||
|
) => {
|
||||||
|
Lambda.foreignFunctionInterface(lambdaValue, argArray, environment, Expression.reduceExpression)
|
||||||
|
}
|
||||||
|
|
||||||
|
let defaultEnvironment = ExpressionValue.defaultEnvironment
|
||||||
|
|
||||||
|
let defaultExternalBindings = ExpressionValue.defaultExternalBindings
|
||||||
|
|
|
@ -9,6 +9,8 @@ type errorValue = Reducer_ErrorValue.errorValue
|
||||||
type expressionValue = ReducerInterface_ExpressionValue.expressionValue
|
type expressionValue = ReducerInterface_ExpressionValue.expressionValue
|
||||||
@genType
|
@genType
|
||||||
type externalBindings = ReducerInterface_ExpressionValue.externalBindings
|
type externalBindings = ReducerInterface_ExpressionValue.externalBindings
|
||||||
|
@genType
|
||||||
|
type lambdaValue = ReducerInterface_ExpressionValue.lambdaValue
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
let evaluateUsingOptions: (
|
let evaluateUsingOptions: (
|
||||||
|
@ -26,3 +28,16 @@ let evaluatePartialUsingExternalBindings: (
|
||||||
let evaluate: string => result<expressionValue, errorValue>
|
let evaluate: string => result<expressionValue, errorValue>
|
||||||
|
|
||||||
let parse: string => result<Expression.expression, errorValue>
|
let parse: string => result<Expression.expression, errorValue>
|
||||||
|
|
||||||
|
@genType
|
||||||
|
let foreignFunctionInterface: (
|
||||||
|
QuriSquiggleLang.ReducerInterface_ExpressionValue.lambdaValue,
|
||||||
|
array<QuriSquiggleLang.ReducerInterface_ExpressionValue.expressionValue>,
|
||||||
|
QuriSquiggleLang.ReducerInterface_ExpressionValue.environment,
|
||||||
|
) => result<expressionValue, errorValue>
|
||||||
|
|
||||||
|
@genType
|
||||||
|
let defaultEnvironment: environment
|
||||||
|
|
||||||
|
@genType
|
||||||
|
let defaultExternalBindings: externalBindings
|
||||||
|
|
|
@ -57,3 +57,13 @@ let applyParametersToLambda = (
|
||||||
|
|
||||||
let doLambdaCall = (lambdaValue: ExpressionValue.lambdaValue, args, environment, reducer) =>
|
let doLambdaCall = (lambdaValue: ExpressionValue.lambdaValue, args, environment, reducer) =>
|
||||||
applyParametersToLambda(lambdaValue, args, environment, reducer)
|
applyParametersToLambda(lambdaValue, args, environment, reducer)
|
||||||
|
|
||||||
|
let foreignFunctionInterface = (
|
||||||
|
lambdaValue: ExpressionValue.lambdaValue,
|
||||||
|
argArray: array<expressionValue>,
|
||||||
|
environment: ExpressionValue.environment,
|
||||||
|
reducer: ExpressionT.reducerFn,
|
||||||
|
): result<expressionValue, 'e> => {
|
||||||
|
let args = argArray->Belt.List.fromArray
|
||||||
|
applyParametersToLambda(lambdaValue, args, environment, reducer)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user