From 3106a10b9081ab9dd50a475a0e88873bbae7922a Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 4 Sep 2022 15:21:07 +0200 Subject: [PATCH] tweak: Move new functions to the "Danger" namespace --- .../FunctionRegistry_Library.res | 1 + .../FunctionRegistry/Library/FR_Danger.res | 45 +++++++++++++++++++ .../FunctionRegistry/Library/FR_Number.res | 12 ----- 3 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Danger.res diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res index a12c4a36..3714b0b7 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res @@ -1,6 +1,7 @@ let fnList = Belt.Array.concatMany([ FR_Dict.library, FR_Dist.library, + FR_Danger.library, FR_Fn.library, FR_Sampleset.library, FR_List.library, diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Danger.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Danger.res new file mode 100644 index 00000000..59ae77cb --- /dev/null +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Danger.res @@ -0,0 +1,45 @@ +open FunctionRegistry_Core +open FunctionRegistry_Helpers + +let nameSpace = "Danger" +let requiresNamespace = true + +module TwoNumbersToNumber = { + let make = (name, fn) => + FnDefinition.make( + ~name, + ~inputs=[FRTypeNumber, FRTypeNumber], + ~run=(_, inputs, _, _) => { + inputs->Prepare.ToValueTuple.twoNumbers->E.R2.fmap(fn)->E.R2.fmap(Wrappers.evNumber) + }, + (), + ) +} + +module ThreeNumbersToNumber = { + let make = (name, fn) => + FnDefinition.make( + ~name, + ~inputs=[FRTypeNumber, FRTypeNumber, FRTypeNumber], + ~run=(_, inputs, _, _) => { + inputs->Prepare.ToValueTuple.threeNumbers->E.R2.fmap(fn)->E.R2.fmap(Wrappers.evNumber) + }, + (), + ) +} + +let library = [ + Function.make( + ~name="laplace", + ~nameSpace, + ~requiresNamespace, + ~output=EvtNumber, + ~examples=[`laplace(1, 20)`], + ~definitions=[ + TwoNumbersToNumber.make("laplace", ((successes, trials)) => + (successes +. 1.0) /. (trials +. 1.0) + ), + ], + (), + ), +] diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Number.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Number.res index 48fdc67f..472ae60b 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Number.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Number.res @@ -20,18 +20,6 @@ module NumberToNumber = { ) } -module TwoNumbersToNumber = { - let make = (name, fn) => - FnDefinition.make( - ~name, - ~inputs=[FRTypeNumber, FRTypeNumber], - ~run=(_, inputs, _, _) => { - inputs->Prepare.ToValueTuple.twoNumbers->E.R2.fmap(fn)->E.R2.fmap(Wrappers.evNumber) - }, - (), - ) -} - module ArrayNumberDist = { let make = (name, fn) => { FnDefinition.make(