Simple reformatting, got RequiresNamespace to work
This commit is contained in:
parent
0c032e710c
commit
d88fb95767
|
@ -18,11 +18,11 @@ module FooImplementation = {
|
||||||
let fn = Function.make(
|
let fn = Function.make(
|
||||||
~name="add",
|
~name="add",
|
||||||
~nameSpace="Foo",
|
~nameSpace="Foo",
|
||||||
|
~requiresNamespace=false,
|
||||||
~examples=["Foo.add(1, 2)", "Foo.add(1, 2, 3)"],
|
~examples=["Foo.add(1, 2)", "Foo.add(1, 2, 3)"],
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=false,
|
|
||||||
~name="add",
|
~name="add",
|
||||||
~inputs=[FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeNumber, FRTypeNumber],
|
||||||
~run=(_, inputs, _) =>
|
~run=(_, inputs, _) =>
|
||||||
|
@ -33,7 +33,6 @@ module FooImplementation = {
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=true,
|
|
||||||
~name="add",
|
~name="add",
|
||||||
~inputs=[FRTypeNumber, FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeNumber, FRTypeNumber, FRTypeNumber],
|
||||||
~run=(_, inputs, _) =>
|
~run=(_, inputs, _) =>
|
||||||
|
@ -92,4 +91,4 @@ describe("Fn auto-testing", () => {
|
||||||
let expectedOutputType = FooImplementation.fn.output |> E.O.toExn("")
|
let expectedOutputType = FooImplementation.fn.output |> E.O.toExn("")
|
||||||
expect(responseType)->toEqual(Ok(expectedOutputType))
|
expect(responseType)->toEqual(Ok(expectedOutputType))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -41,7 +41,6 @@ and frValueDictParam = (string, frValue)
|
||||||
and frValueDistOrNumber = FRValueNumber(float) | FRValueDist(DistributionTypes.genericDist)
|
and frValueDistOrNumber = FRValueNumber(float) | FRValueDist(DistributionTypes.genericDist)
|
||||||
|
|
||||||
type fnDefinition = {
|
type fnDefinition = {
|
||||||
requiresNamespace: bool,
|
|
||||||
name: string,
|
name: string,
|
||||||
inputs: array<frType>,
|
inputs: array<frType>,
|
||||||
run: (
|
run: (
|
||||||
|
@ -54,6 +53,7 @@ type fnDefinition = {
|
||||||
type function = {
|
type function = {
|
||||||
name: string,
|
name: string,
|
||||||
definitions: array<fnDefinition>,
|
definitions: array<fnDefinition>,
|
||||||
|
requiresNamespace: bool,
|
||||||
nameSpace: string,
|
nameSpace: string,
|
||||||
output: option<internalExpressionValueType>,
|
output: option<internalExpressionValueType>,
|
||||||
examples: array<string>,
|
examples: array<string>,
|
||||||
|
@ -352,9 +352,8 @@ module FnDefinition = {
|
||||||
let toLambda = (t: t) =>
|
let toLambda = (t: t) =>
|
||||||
Reducer_Module.convertOptionToFfiFn(t.name, toFfiFn(t))->Reducer_Module.eLambdaFFIValue
|
Reducer_Module.convertOptionToFfiFn(t.name, toFfiFn(t))->Reducer_Module.eLambdaFFIValue
|
||||||
|
|
||||||
let make = (~requiresNamespace=true, ~name, ~inputs, ~run, ()): t => {
|
let make = (~name, ~inputs, ~run, ()): t => {
|
||||||
name: name,
|
name: name,
|
||||||
requiresNamespace: requiresNamespace,
|
|
||||||
inputs: inputs,
|
inputs: inputs,
|
||||||
run: run,
|
run: run,
|
||||||
}
|
}
|
||||||
|
@ -374,6 +373,7 @@ module Function = {
|
||||||
let make = (
|
let make = (
|
||||||
~name,
|
~name,
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~definitions,
|
~definitions,
|
||||||
~examples=?,
|
~examples=?,
|
||||||
~output=?,
|
~output=?,
|
||||||
|
@ -387,6 +387,7 @@ module Function = {
|
||||||
output: output,
|
output: output,
|
||||||
examples: examples |> E.O.default([]),
|
examples: examples |> E.O.default([]),
|
||||||
isExperimental: isExperimental,
|
isExperimental: isExperimental,
|
||||||
|
requiresNamespace: requiresNamespace,
|
||||||
description: description,
|
description: description,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,6 +428,9 @@ module NameSpace = {
|
||||||
|
|
||||||
module Registry = {
|
module Registry = {
|
||||||
let toJson = (r: registry) => r->E.A2.fmap(Function.toJson)
|
let toJson = (r: registry) => r->E.A2.fmap(Function.toJson)
|
||||||
|
|
||||||
|
let exportedSubset = (r: registry): registry => r |> E.A.filter(r => !r.requiresNamespace)
|
||||||
|
|
||||||
let definitionsWithFunctions = (r: registry) =>
|
let definitionsWithFunctions = (r: registry) =>
|
||||||
r->E.A2.fmap(fn => fn.definitions->E.A2.fmap(def => (def, fn)))->E.A.concatMany
|
r->E.A2.fmap(fn => fn.definitions->E.A2.fmap(def => (def, fn)))->E.A.concatMany
|
||||||
|
|
||||||
|
@ -442,7 +446,6 @@ module Registry = {
|
||||||
~env: GenericDist.env,
|
~env: GenericDist.env,
|
||||||
) => {
|
) => {
|
||||||
let matchToDef = m => Matcher.Registry.matchToDef(registry, m)
|
let matchToDef = m => Matcher.Registry.matchToDef(registry, m)
|
||||||
//Js.log(toSimple(registry))
|
|
||||||
let showNameMatchDefinitions = matches => {
|
let showNameMatchDefinitions = matches => {
|
||||||
let defs =
|
let defs =
|
||||||
matches
|
matches
|
||||||
|
@ -460,17 +463,16 @@ module Registry = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo: get namespace from project.
|
|
||||||
let allNamespaces = (t: registry) => t->E.A2.fmap(r => r.nameSpace)->E.A.uniq
|
let allNamespaces = (t: registry) => t->E.A2.fmap(r => r.nameSpace)->E.A.uniq
|
||||||
|
|
||||||
let makeModules = (prevBindings: Reducer_Module.t, t: registry): Reducer_Module.t => {
|
let makeModules = (prevBindings: Reducer_Module.t, t: registry): Reducer_Module.t => {
|
||||||
let nameSpaces = allNamespaces(t)
|
let nameSpaces = allNamespaces(t)
|
||||||
let nameSpaceBindings = nameSpaces->E.A2.fmap(nameSpace => {
|
let nameSpaceBindings = nameSpaces->E.A2.fmap(nameSpace => {
|
||||||
let foo: NameSpace.t = {
|
let namespaceModule: NameSpace.t = {
|
||||||
name: nameSpace,
|
name: nameSpace,
|
||||||
functions: t->E.A2.filter(r => r.nameSpace == nameSpace),
|
functions: t->E.A2.filter(r => r.nameSpace == nameSpace),
|
||||||
}
|
}
|
||||||
(nameSpace, NameSpace.toModule(foo))
|
(nameSpace, NameSpace.toModule(namespaceModule))
|
||||||
})
|
})
|
||||||
E.A.reduce(nameSpaceBindings, prevBindings, (acc, (name, fn)) =>
|
E.A.reduce(nameSpaceBindings, prevBindings, (acc, (name, fn)) =>
|
||||||
acc->Reducer_Module.defineModule(name, fn)
|
acc->Reducer_Module.defineModule(name, fn)
|
||||||
|
|
|
@ -5,5 +5,5 @@ let registry = Belt.Array.concatMany([
|
||||||
FR_List.library,
|
FR_List.library,
|
||||||
FR_Number.library,
|
FR_Number.library,
|
||||||
FR_Pointset.library,
|
FR_Pointset.library,
|
||||||
FR_Scoring.library
|
FR_Scoring.library,
|
||||||
])
|
])
|
||||||
|
|
|
@ -45,11 +45,11 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="merge",
|
~name="merge",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace=true,
|
||||||
~output=EvtRecord,
|
~output=EvtRecord,
|
||||||
~examples=[`Dict.merge({a: 1, b: 2}, {c: 3, d: 4})`],
|
~examples=[`Dict.merge({a: 1, b: 2}, {c: 3, d: 4})`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=true,
|
|
||||||
~name="merge",
|
~name="merge",
|
||||||
~inputs=[FRTypeDict(FRTypeAny), FRTypeDict(FRTypeAny)],
|
~inputs=[FRTypeDict(FRTypeAny), FRTypeDict(FRTypeAny)],
|
||||||
~run=(inputs, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
|
@ -67,11 +67,11 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="mergeMany",
|
~name="mergeMany",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace=true,
|
||||||
~output=EvtRecord,
|
~output=EvtRecord,
|
||||||
~examples=[`Dict.mergeMany([{a: 1, b: 2}, {c: 3, d: 4}])`],
|
~examples=[`Dict.mergeMany([{a: 1, b: 2}, {c: 3, d: 4}])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=true,
|
|
||||||
~name="mergeMany",
|
~name="mergeMany",
|
||||||
~inputs=[FRTypeArray(FRTypeDict(FRTypeAny))],
|
~inputs=[FRTypeArray(FRTypeDict(FRTypeAny))],
|
||||||
~run=(_, inputs, _) =>
|
~run=(_, inputs, _) =>
|
||||||
|
@ -89,11 +89,11 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="keys",
|
~name="keys",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace=true,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
~examples=[`Dict.keys({a: 1, b: 2})`],
|
~examples=[`Dict.keys({a: 1, b: 2})`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=true,
|
|
||||||
~name="keys",
|
~name="keys",
|
||||||
~inputs=[FRTypeDict(FRTypeAny)],
|
~inputs=[FRTypeDict(FRTypeAny)],
|
||||||
~run=(inputs, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
|
@ -109,11 +109,11 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="values",
|
~name="values",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace=true,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
~examples=[`Dict.values({a: 1, b: 2})`],
|
~examples=[`Dict.values({a: 1, b: 2})`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=true,
|
|
||||||
~name="values",
|
~name="values",
|
||||||
~inputs=[FRTypeDict(FRTypeAny)],
|
~inputs=[FRTypeDict(FRTypeAny)],
|
||||||
~run=(inputs, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
|
@ -129,11 +129,11 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="toList",
|
~name="toList",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace=true,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
~examples=[`Dict.toList({a: 1, b: 2})`],
|
~examples=[`Dict.toList({a: 1, b: 2})`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=true,
|
|
||||||
~name="toList",
|
~name="toList",
|
||||||
~inputs=[FRTypeDict(FRTypeAny)],
|
~inputs=[FRTypeDict(FRTypeAny)],
|
||||||
~run=(inputs, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
|
@ -149,11 +149,11 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="fromList",
|
~name="fromList",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace=true,
|
||||||
~output=EvtRecord,
|
~output=EvtRecord,
|
||||||
~examples=[`Dict.fromList({a: 1, b: 2})`],
|
~examples=[`Dict.fromList({a: 1, b: 2})`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=true,
|
|
||||||
~name="fromList",
|
~name="fromList",
|
||||||
~inputs=[FRTypeArray(FRTypeArray(FRTypeAny))],
|
~inputs=[FRTypeArray(FRTypeArray(FRTypeAny))],
|
||||||
~run=(inputs, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
|
|
|
@ -5,9 +5,10 @@ let twoArgs = E.Tuple2.toFnCall
|
||||||
module DistributionCreation = {
|
module DistributionCreation = {
|
||||||
let nameSpace = "Dist"
|
let nameSpace = "Dist"
|
||||||
let output = ReducerInterface_InternalExpressionValue.EvtDistribution
|
let output = ReducerInterface_InternalExpressionValue.EvtDistribution
|
||||||
|
let requiresNamespace = false
|
||||||
|
|
||||||
let fnMake = (~name, ~examples, ~definitions) => {
|
let fnMake = (~name, ~examples, ~definitions) => {
|
||||||
Function.make(~name, ~nameSpace, ~output, ~examples, ~definitions, ())
|
Function.make(~name, ~nameSpace, ~output, ~examples, ~definitions, ~requiresNamespace, ())
|
||||||
}
|
}
|
||||||
|
|
||||||
module TwoArgDist = {
|
module TwoArgDist = {
|
||||||
|
@ -18,7 +19,6 @@ module DistributionCreation = {
|
||||||
|
|
||||||
let make = (name, fn) => {
|
let make = (name, fn) => {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=false,
|
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeDistOrNumber, FRTypeDistOrNumber],
|
~inputs=[FRTypeDistOrNumber, FRTypeDistOrNumber],
|
||||||
~run=(_, inputs, env) => inputs->Prepare.ToValueTuple.twoDistOrNumber->process(~fn, ~env),
|
~run=(_, inputs, env) => inputs->Prepare.ToValueTuple.twoDistOrNumber->process(~fn, ~env),
|
||||||
|
@ -28,7 +28,6 @@ module DistributionCreation = {
|
||||||
|
|
||||||
let makeRecordP5P95 = (name, fn) => {
|
let makeRecordP5P95 = (name, fn) => {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=false,
|
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeRecord([("p5", FRTypeDistOrNumber), ("p95", FRTypeDistOrNumber)])],
|
~inputs=[FRTypeRecord([("p5", FRTypeDistOrNumber), ("p95", FRTypeDistOrNumber)])],
|
||||||
~run=(_, inputs, env) =>
|
~run=(_, inputs, env) =>
|
||||||
|
@ -40,7 +39,6 @@ module DistributionCreation = {
|
||||||
let makeRecordMeanStdev = (name, fn) => {
|
let makeRecordMeanStdev = (name, fn) => {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~requiresNamespace=false,
|
|
||||||
~inputs=[FRTypeRecord([("mean", FRTypeDistOrNumber), ("stdev", FRTypeDistOrNumber)])],
|
~inputs=[FRTypeRecord([("mean", FRTypeDistOrNumber), ("stdev", FRTypeDistOrNumber)])],
|
||||||
~run=(_, inputs, env) =>
|
~run=(_, inputs, env) =>
|
||||||
inputs->Prepare.ToValueTuple.Record.twoDistOrNumber->process(~fn, ~env),
|
inputs->Prepare.ToValueTuple.Record.twoDistOrNumber->process(~fn, ~env),
|
||||||
|
@ -57,7 +55,6 @@ module DistributionCreation = {
|
||||||
|
|
||||||
let make = (name, fn) =>
|
let make = (name, fn) =>
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=false,
|
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeDistOrNumber],
|
~inputs=[FRTypeDistOrNumber],
|
||||||
~run=(_, inputs, env) => inputs->Prepare.ToValueTuple.oneDistOrNumber->process(~fn, ~env),
|
~run=(_, inputs, env) => inputs->Prepare.ToValueTuple.oneDistOrNumber->process(~fn, ~env),
|
||||||
|
@ -152,4 +149,4 @@ module DistributionCreation = {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
let library = DistributionCreation.library
|
let library = DistributionCreation.library
|
||||||
|
|
|
@ -34,6 +34,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="declare",
|
~name="declare",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace=true,
|
||||||
~description="Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within.",
|
~description="Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within.",
|
||||||
~examples=[
|
~examples=[
|
||||||
`declareFn({
|
`declareFn({
|
||||||
|
@ -47,7 +48,6 @@ let library = [
|
||||||
~isExperimental=true,
|
~isExperimental=true,
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=true,
|
|
||||||
~name="declare",
|
~name="declare",
|
||||||
~inputs=[Declaration.frType],
|
~inputs=[Declaration.frType],
|
||||||
~run=(_, inputs, _) => {
|
~run=(_, inputs, _) => {
|
||||||
|
|
|
@ -29,12 +29,12 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="make",
|
~name="make",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
~examples=[`List.make(2, "testValue")`],
|
~examples=[`List.make(2, "testValue")`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
//Todo: If the second item is a function with no args, it could be nice to run this function and return the result.
|
//Todo: If the second item is a function with no args, it could be nice to run this function and return the result.
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace,
|
|
||||||
~name="make",
|
~name="make",
|
||||||
~inputs=[FRTypeNumber, FRTypeAny],
|
~inputs=[FRTypeNumber, FRTypeAny],
|
||||||
~run=(inputs, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
|
@ -51,11 +51,11 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="upTo",
|
~name="upTo",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
~examples=[`List.upTo(1,4)`],
|
~examples=[`List.upTo(1,4)`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace,
|
|
||||||
~name="upTo",
|
~name="upTo",
|
||||||
~inputs=[FRTypeNumber, FRTypeNumber],
|
~inputs=[FRTypeNumber, FRTypeNumber],
|
||||||
~run=(_, inputs, _) =>
|
~run=(_, inputs, _) =>
|
||||||
|
@ -70,10 +70,10 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="first",
|
~name="first",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~examples=[`List.first([1,4,5])`],
|
~examples=[`List.first([1,4,5])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace,
|
|
||||||
~name="first",
|
~name="first",
|
||||||
~inputs=[FRTypeArray(FRTypeAny)],
|
~inputs=[FRTypeArray(FRTypeAny)],
|
||||||
~run=(inputs, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
|
@ -89,10 +89,10 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="last",
|
~name="last",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~examples=[`List.last([1,4,5])`],
|
~examples=[`List.last([1,4,5])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=false,
|
|
||||||
~name="last",
|
~name="last",
|
||||||
~inputs=[FRTypeArray(FRTypeAny)],
|
~inputs=[FRTypeArray(FRTypeAny)],
|
||||||
~run=(inputs, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
|
@ -109,10 +109,10 @@ let library = [
|
||||||
~name="reverse",
|
~name="reverse",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
|
~requiresNamespace=false,
|
||||||
~examples=[`List.reverse([1,4,5])`],
|
~examples=[`List.reverse([1,4,5])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=false,
|
|
||||||
~name="reverse",
|
~name="reverse",
|
||||||
~inputs=[FRTypeArray(FRTypeAny)],
|
~inputs=[FRTypeArray(FRTypeAny)],
|
||||||
~run=(inputs, _, _) =>
|
~run=(inputs, _, _) =>
|
||||||
|
|
|
@ -7,7 +7,6 @@ let requiresNamespace = false
|
||||||
module NumberToNumber = {
|
module NumberToNumber = {
|
||||||
let make = (name, fn) =>
|
let make = (name, fn) =>
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace,
|
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeNumber],
|
~inputs=[FRTypeNumber],
|
||||||
~run=(_, inputs, _) => {
|
~run=(_, inputs, _) => {
|
||||||
|
@ -24,7 +23,6 @@ module NumberToNumber = {
|
||||||
module ArrayNumberDist = {
|
module ArrayNumberDist = {
|
||||||
let make = (name, fn) => {
|
let make = (name, fn) => {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace=false,
|
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeArray(FRTypeNumber)],
|
~inputs=[FRTypeArray(FRTypeNumber)],
|
||||||
~run=(_, inputs, _) =>
|
~run=(_, inputs, _) =>
|
||||||
|
@ -51,6 +49,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="floor",
|
~name="floor",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`floor(3.5)`],
|
~examples=[`floor(3.5)`],
|
||||||
~definitions=[NumberToNumber.make("floor", Js.Math.floor_float)],
|
~definitions=[NumberToNumber.make("floor", Js.Math.floor_float)],
|
||||||
|
@ -59,6 +58,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="ceiling",
|
~name="ceiling",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`ceiling(3.5)`],
|
~examples=[`ceiling(3.5)`],
|
||||||
~definitions=[NumberToNumber.make("ceil", Js.Math.ceil_float)],
|
~definitions=[NumberToNumber.make("ceil", Js.Math.ceil_float)],
|
||||||
|
@ -67,6 +67,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="absolute value",
|
~name="absolute value",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`abs(3.5)`],
|
~examples=[`abs(3.5)`],
|
||||||
~definitions=[NumberToNumber.make("abs", Js.Math.abs_float)],
|
~definitions=[NumberToNumber.make("abs", Js.Math.abs_float)],
|
||||||
|
@ -75,6 +76,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="exponent",
|
~name="exponent",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`exp(3.5)`],
|
~examples=[`exp(3.5)`],
|
||||||
~definitions=[NumberToNumber.make("exp", Js.Math.exp)],
|
~definitions=[NumberToNumber.make("exp", Js.Math.exp)],
|
||||||
|
@ -83,6 +85,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="log",
|
~name="log",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`log(3.5)`],
|
~examples=[`log(3.5)`],
|
||||||
~definitions=[NumberToNumber.make("log", Js.Math.log)],
|
~definitions=[NumberToNumber.make("log", Js.Math.log)],
|
||||||
|
@ -91,6 +94,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="log base 10",
|
~name="log base 10",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`log10(3.5)`],
|
~examples=[`log10(3.5)`],
|
||||||
~definitions=[NumberToNumber.make("log10", Js.Math.log10)],
|
~definitions=[NumberToNumber.make("log10", Js.Math.log10)],
|
||||||
|
@ -99,6 +103,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="log base 2",
|
~name="log base 2",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`log2(3.5)`],
|
~examples=[`log2(3.5)`],
|
||||||
~definitions=[NumberToNumber.make("log2", Js.Math.log2)],
|
~definitions=[NumberToNumber.make("log2", Js.Math.log2)],
|
||||||
|
@ -107,6 +112,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="round",
|
~name="round",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`round(3.5)`],
|
~examples=[`round(3.5)`],
|
||||||
~definitions=[NumberToNumber.make("round", Js.Math.round)],
|
~definitions=[NumberToNumber.make("round", Js.Math.round)],
|
||||||
|
@ -115,6 +121,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="sum",
|
~name="sum",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`sum([3,5,2])`],
|
~examples=[`sum([3,5,2])`],
|
||||||
~definitions=[ArrayNumberDist.make("sum", r => r->E.A.Floats.sum->Wrappers.evNumber->Ok)],
|
~definitions=[ArrayNumberDist.make("sum", r => r->E.A.Floats.sum->Wrappers.evNumber->Ok)],
|
||||||
|
@ -123,6 +130,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="product",
|
~name="product",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`product([3,5,2])`],
|
~examples=[`product([3,5,2])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
|
@ -133,6 +141,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="min",
|
~name="min",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`min([3,5,2])`],
|
~examples=[`min([3,5,2])`],
|
||||||
~definitions=[ArrayNumberDist.make("min", r => r->E.A.Floats.min->Wrappers.evNumber->Ok)],
|
~definitions=[ArrayNumberDist.make("min", r => r->E.A.Floats.min->Wrappers.evNumber->Ok)],
|
||||||
|
@ -141,6 +150,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="max",
|
~name="max",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`max([3,5,2])`],
|
~examples=[`max([3,5,2])`],
|
||||||
~definitions=[ArrayNumberDist.make("max", r => r->E.A.Floats.max->Wrappers.evNumber->Ok)],
|
~definitions=[ArrayNumberDist.make("max", r => r->E.A.Floats.max->Wrappers.evNumber->Ok)],
|
||||||
|
@ -149,6 +159,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="mean",
|
~name="mean",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`mean([3,5,2])`],
|
~examples=[`mean([3,5,2])`],
|
||||||
~definitions=[ArrayNumberDist.make("mean", r => r->E.A.Floats.mean->Wrappers.evNumber->Ok)],
|
~definitions=[ArrayNumberDist.make("mean", r => r->E.A.Floats.mean->Wrappers.evNumber->Ok)],
|
||||||
|
@ -157,6 +168,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="geometric mean",
|
~name="geometric mean",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`geomean([3,5,2])`],
|
~examples=[`geomean([3,5,2])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
|
@ -167,6 +179,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="standard deviation",
|
~name="standard deviation",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`stdev([3,5,2,3,5])`],
|
~examples=[`stdev([3,5,2,3,5])`],
|
||||||
~definitions=[ArrayNumberDist.make("stdev", r => r->E.A.Floats.stdev->Wrappers.evNumber->Ok)],
|
~definitions=[ArrayNumberDist.make("stdev", r => r->E.A.Floats.stdev->Wrappers.evNumber->Ok)],
|
||||||
|
@ -175,6 +188,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="variance",
|
~name="variance",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[`variance([3,5,2,3,5])`],
|
~examples=[`variance([3,5,2,3,5])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
|
@ -185,6 +199,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="sort",
|
~name="sort",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
~examples=[`sort([3,5,2,3,5])`],
|
~examples=[`sort([3,5,2,3,5])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
|
@ -197,6 +212,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="cumulative sum",
|
~name="cumulative sum",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
~examples=[`cumsum([3,5,2,3,5])`],
|
~examples=[`cumsum([3,5,2,3,5])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
|
@ -209,6 +225,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="cumulative prod",
|
~name="cumulative prod",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
~examples=[`cumprod([3,5,2,3,5])`],
|
~examples=[`cumprod([3,5,2,3,5])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
|
@ -221,6 +238,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="diff",
|
~name="diff",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
~examples=[`diff([3,5,2,3,5])`],
|
~examples=[`diff([3,5,2,3,5])`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
|
|
|
@ -27,9 +27,9 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="makeContinuous",
|
~name="makeContinuous",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace,
|
|
||||||
~name="makeContinuous",
|
~name="makeContinuous",
|
||||||
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
||||||
~run=(_, inputs, _) => inputsTodist(inputs, r => Continuous(Continuous.make(r))),
|
~run=(_, inputs, _) => inputsTodist(inputs, r => Continuous(Continuous.make(r))),
|
||||||
|
@ -41,9 +41,9 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="makeDiscrete",
|
~name="makeDiscrete",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace,
|
|
||||||
~name="makeDiscrete",
|
~name="makeDiscrete",
|
||||||
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
||||||
~run=(_, inputs, _) => inputsTodist(inputs, r => Discrete(Discrete.make(r))),
|
~run=(_, inputs, _) => inputsTodist(inputs, r => Discrete(Discrete.make(r))),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
open FunctionRegistry_Core
|
open FunctionRegistry_Core
|
||||||
|
|
||||||
let nameSpace = "Dist"
|
let nameSpace = "Dist"
|
||||||
let requiresNamespace = false
|
let requiresNamespace = true
|
||||||
|
|
||||||
let runScoring = (estimate, answer, prior, env) => {
|
let runScoring = (estimate, answer, prior, env) => {
|
||||||
GenericDist.Score.logScore(~estimate, ~answer, ~prior, ~env)
|
GenericDist.Score.logScore(~estimate, ~answer, ~prior, ~env)
|
||||||
|
@ -13,6 +13,7 @@ let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="logScore",
|
~name="logScore",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
~requiresNamespace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
~examples=[
|
~examples=[
|
||||||
"Dist.logScore({estimate: normal(5,2), answer: normal(5.2,1)}, prior: normal(5.5,3)})",
|
"Dist.logScore({estimate: normal(5,2), answer: normal(5.2,1)}, prior: normal(5.5,3)})",
|
||||||
|
@ -21,7 +22,6 @@ let library = [
|
||||||
],
|
],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~requiresNamespace,
|
|
||||||
~name="logScore",
|
~name="logScore",
|
||||||
~inputs=[
|
~inputs=[
|
||||||
FRTypeRecord([
|
FRTypeRecord([
|
||||||
|
@ -48,7 +48,6 @@ let library = [
|
||||||
),
|
),
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="logScore",
|
~name="logScore",
|
||||||
~requiresNamespace,
|
|
||||||
~inputs=[FRTypeRecord([("estimate", FRTypeDist), ("answer", FRTypeDistOrNumber)])],
|
~inputs=[FRTypeRecord([("estimate", FRTypeDist), ("answer", FRTypeDistOrNumber)])],
|
||||||
~run=(_, inputs, env) => {
|
~run=(_, inputs, env) => {
|
||||||
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs(inputs) {
|
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs(inputs) {
|
||||||
|
@ -69,11 +68,11 @@ let library = [
|
||||||
~name="klDivergence",
|
~name="klDivergence",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
~output=EvtNumber,
|
~output=EvtNumber,
|
||||||
|
~requiresNamespace,
|
||||||
~examples=["Dist.klDivergence(normal(5,2), normal(5,1.5)"],
|
~examples=["Dist.klDivergence(normal(5,2), normal(5,1.5)"],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="klDivergence",
|
~name="klDivergence",
|
||||||
~requiresNamespace,
|
|
||||||
~inputs=[FRTypeDist, FRTypeDist],
|
~inputs=[FRTypeDist, FRTypeDist],
|
||||||
~run=(_, inputs, env) => {
|
~run=(_, inputs, env) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
|
|
|
@ -18,9 +18,12 @@ type internalExpressionValue = InternalExpressionValue.t
|
||||||
let registry = FunctionRegistry_Library.registry
|
let registry = FunctionRegistry_Library.registry
|
||||||
|
|
||||||
let tryRegistry = ((fnName, args): InternalExpressionValue.functionCall, env) => {
|
let tryRegistry = ((fnName, args): InternalExpressionValue.functionCall, env) => {
|
||||||
FunctionRegistry_Core.Registry.matchAndRun(~registry, ~fnName, ~args, ~env)->E.O2.fmap(
|
FunctionRegistry_Core.Registry.matchAndRun(
|
||||||
E.R2.errMap(_, s => Reducer_ErrorValue.RETodo(s)),
|
~registry=FunctionRegistry_Core.Registry.exportedSubset(registry),
|
||||||
)
|
~fnName,
|
||||||
|
~args,
|
||||||
|
~env,
|
||||||
|
)->E.O2.fmap(E.R2.errMap(_, s => Reducer_ErrorValue.RETodo(s)))
|
||||||
}
|
}
|
||||||
|
|
||||||
let dispatch = (call: InternalExpressionValue.functionCall, environment, chain): result<
|
let dispatch = (call: InternalExpressionValue.functionCall, environment, chain): result<
|
||||||
|
|
Loading…
Reference in New Issue
Block a user