From 62488185312c48e433cea495f0990a4cae6a63c9 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Mon, 23 May 2022 20:49:10 -0400 Subject: [PATCH 01/15] First attempt at function declaration --- .../FunctionRegistry_Core.res | 31 +++++++++- .../FunctionRegistry_Core.resi | 58 ------------------- .../FunctionRegistry_Helpers.res | 7 +++ .../FunctionRegistry_Library.res | 20 +++++++ .../squiggle-lang/src/rescript/Utility/E.res | 1 + 5 files changed, 57 insertions(+), 60 deletions(-) delete mode 100644 packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.resi diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res index 99ecc78f..a88ce239 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res @@ -8,9 +8,12 @@ type rec frType = | FRTypeNumber | FRTypeNumeric | FRTypeDistOrNumber + | FRTLambda | FRTypeRecord(frTypeRecord) - | FRTypeArray(array) + | FRTypeArray(frType) | FRTypeOption(frType) + | FRTypeString + | FRTypeVariant(array) and frTypeRecord = array and frTypeRecordParam = (string, frType) @@ -22,8 +25,12 @@ type rec frValue = | FRValueNumber(float) | FRValueDist(DistributionTypes.genericDist) | FRValueOption(option) + | FRValueArray(array) | FRValueDistOrNumber(frValueDistOrNumber) | FRValueRecord(frValueRecord) + | FRValueLambda(ReducerInterface_ExpressionValue.lambdaValue) + | FRValueString(string) + | FRValueVariant(string) and frValueRecord = array and frValueRecordParam = (string, frValue) and frValueDistOrNumber = FRValueNumber(float) | FRValueDist(DistributionTypes.genericDist) @@ -52,8 +59,9 @@ module FRType = { let input = ((name, frType): frTypeRecordParam) => `${name}: ${toString(frType)}` `record({${r->E.A2.fmap(input)->E.A2.joinWith(", ")}})` } - | FRTypeArray(r) => `record(${r->E.A2.fmap(toString)->E.A2.joinWith(", ")})` + | FRTypeArray(r) => `record(${toString(r)})` | FRTypeOption(v) => `option(${toString(v)})` + | FRTLambda => `lambda` } let rec matchWithExpressionValue = (t: t, r: expressionValue): option => @@ -66,6 +74,7 @@ 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)) | (FRTypeRecord(recordParams), EvRecord(record)) => { let getAndMatch = (name, input) => E.Dict.get(record, name)->E.O.bind(matchWithExpressionValue(input)) @@ -80,6 +89,24 @@ module FRType = { | _ => None } + let rec matchReverse = (e: frValue): expressionValue => + switch(e){ + | FRValueNumber(f) => (EvNumber(f)) + | FRValueDistOrNumber(FRValueNumber(n)) => EvNumber(n) + | FRValueDistOrNumber(FRValueDist(n)) => EvDistribution(n) + | FRValueDist(dist) => EvDistribution(dist) + | FRValueOption(Some(r)) => matchReverse(r) + | FRValueArray(elements) => EvArray(elements->E.A2.fmap(matchReverse)) + | FRValueRecord(frValueRecord) => { + let record = frValueRecord->E.A2.fmap(((name, value)) => (name, matchReverse(value)))->E.Dict.fromArray + EvRecord(record) + } + | FRValueLambda(l) => EvLambda(l) + | FRValueString(string) => EvString(string) + | FRValueVariant(string) => EvString(string) + } + + // | FRValueOption(None) => break let matchWithExpressionValueArray = (inputs: array, args: array): option< array, > => { diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.resi b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.resi deleted file mode 100644 index 5ca8c708..00000000 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.resi +++ /dev/null @@ -1,58 +0,0 @@ -type expressionValue = ReducerInterface_ExpressionValue.expressionValue - -type rec frType = - | FRTypeNumber - | FRTypeNumeric - | FRTypeDistOrNumber - | FRTypeRecord(frTypeRecord) - | FRTypeArray(array) - | FRTypeOption(frType) -and frTypeRecord = array -and frTypeRecordParam = (string, frType) - -type rec frValue = - | FRValueNumber(float) - | FRValueDist(DistributionTypes.genericDist) - | FRValueOption(option) - | FRValueDistOrNumber(frValueDistOrNumber) - | FRValueRecord(frValueRecord) -and frValueRecord = array -and frValueRecordParam = (string, frValue) -and frValueDistOrNumber = FRValueNumber(float) | FRValueDist(DistributionTypes.genericDist) - -type fnDefinition = { - name: string, - inputs: array, - run: (array, DistributionOperation.env) => result, -} - -type function = { - name: string, - definitions: array, -} - -type registry = array - -// Note: The function "name" is just used for documentation purposes -module Function: { - type t = function - let make: (~name: string, ~definitions: array) => t -} - -module FnDefinition: { - type t = fnDefinition - let make: ( - ~name: string, - ~inputs: array, - ~run: (array, DistributionOperation.env) => result, - ) => t -} - -module Registry: { - let matchAndRun: ( - ~registry: registry, - ~fnName: string, - ~args: array, - ~env: QuriSquiggleLang.DistributionOperation.env, - ) => option> -} diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Helpers.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Helpers.res index 118a15d2..2d21d07a 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Helpers.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Helpers.res @@ -30,6 +30,13 @@ module Prepare = { } } + let twoNumbers = (values: ts): result<(float, float), err> => { + switch values { + | [FRValueNumber(a1), FRValueNumber(a2)] => Ok(a1, a2) + | _ => Error(impossibleError) + } + } + let oneDistOrNumber = (values: ts): result => { switch values { | [FRValueDistOrNumber(a1)] => Ok(a1) diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res index 43be7118..5a12e496 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res @@ -3,7 +3,27 @@ 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)]) 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 + } + ), + ], + ), Function.make( ~name="Normal", ~definitions=[ diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index 3357f4f4..35d9fe4d 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -864,4 +864,5 @@ module Dict = { type t<'a> = Js.Dict.t<'a> let get = Js.Dict.get let keys = Js.Dict.keys + let fromArray = Js.Dict.fromArray } From 31e6f13472e83a3fe974a7c9d123ba408e123efa Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 24 May 2022 07:52:27 -0400 Subject: [PATCH 02/15] Minor cleanup --- .../FunctionRegistry_Core.res | 12 +++- .../FunctionRegistry_Helpers.res | 6 ++ .../FunctionRegistry_Library.res | 60 ++++++++++++++----- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res index a88ce239..da5260c6 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res @@ -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 => @@ -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)) diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Helpers.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Helpers.res index 2d21d07a..d10bbff5 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Helpers.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Helpers.res @@ -19,6 +19,12 @@ module Prepare = { | [FRValueRecord([(_, n1), (_, n2)])] => Ok([n1, n2]) | _ => Error(impossibleError) } + + let toArgs = (inputs: ts): result => + switch inputs { + | [FRValueRecord(args)] => args->E.A2.fmap(((_, b)) => b)->Ok + | _ => Error(impossibleError) + } } } diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res index 5a12e496..d2611b9d 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res @@ -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, + } + + 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( From d1f2f71912fd3904481691008958b012614f8c96 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 24 May 2022 17:02:27 -0400 Subject: [PATCH 03/15] Made formal Declaration type --- .../FunctionRegistry_Library.res | 40 ++++++------------- .../ReducerInterface_ExpressionValue.res | 4 ++ .../src/rescript/Utility/Declaration.res | 33 +++++++++++++++ 3 files changed, 49 insertions(+), 28 deletions(-) create mode 100644 packages/squiggle-lang/src/rescript/Utility/Declaration.res diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res index d2611b9d..fcfd469b 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res @@ -3,39 +3,26 @@ open FunctionRegistry_Helpers let twoArgs = E.Tuple2.toFnCall -module FnDeclaration = { - type range = {min: float, max: float} - let makeRange = (min, max) => {min: min, max: max} - type t = { - fn: ReducerInterface_ExpressionValue.lambdaValue, - args: array, - } - - let validate = (def: t) => { - let {parameters, _} = def.fn - E.A.length(parameters) == E.A.length(def.args) - } - +module Declaration = { 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)])) => { + let fromExpressionValue = (e: frValue): result => { + switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs([e]) { + | Ok([FRValueLambda(lambda), FRValueArray(inputs)]) => { open FunctionRegistry_Helpers.Prepare - let getMinMax = arg => + let getMinMax = arg => ToValueArray.Record.toArgs([arg]) ->E.R.bind(ToValueTuple.twoNumbers) - ->E.R2.fmap(((min, max)) => makeRange(min, max)) + ->E.R2.fmap(((min, max)) => Declaration.ContinuousFloatArg.make(min, max)) inputs ->E.A2.fmap(getMinMax) ->E.A.R.firstErrorOrOpen - ->E.R2.fmap(args => {fn: lambda, args: args}) + ->E.R2.fmap(args => ReducerInterface_ExpressionValue.EvDeclaration( + Declaration.ContinuousDeclaration.make(lambda, args), + )) } | _ => Error("Error") } @@ -46,12 +33,9 @@ let registry = [ Function.make( ~name="FnMake", ~definitions=[ - 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 - }), + FnDefinition.make(~name="declareFn", ~inputs=[Declaration.frType], ~run=(inputs, _) => + inputs->E.A.unsafe_get(0)->Declaration.fromExpressionValue + ), ], ), Function.make( diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res index c9363606..8f3dea42 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res @@ -22,6 +22,7 @@ type rec expressionValue = | EvSymbol(string) | EvDate(Js.Date.t) | EvTimeDuration(float) + | EvDeclaration(lambdaDeclaration) and record = Js.Dict.t and externalBindings = record and lambdaValue = { @@ -29,6 +30,7 @@ and lambdaValue = { context: externalBindings, body: internalCode, } +and lambdaDeclaration = Declaration.declaration @genType let defaultExternalBindings: externalBindings = Js.Dict.empty() @@ -55,6 +57,7 @@ let rec toString = aValue => | EvDistribution(dist) => GenericDist.toString(dist) | EvDate(date) => DateTime.Date.toString(date) | EvTimeDuration(t) => DateTime.Duration.toString(t) + | EvDeclaration(t) => "Declaration" } and toStringRecord = aRecord => { let pairs = @@ -79,6 +82,7 @@ let toStringWithType = aValue => | EvSymbol(_) => `Symbol::${toString(aValue)}` | EvDate(_) => `Date::${toString(aValue)}` | EvTimeDuration(_) => `Date::${toString(aValue)}` + | EvDeclaration(_) => `Declaration::${toString(aValue)}` } let argsToString = (args: array): string => { diff --git a/packages/squiggle-lang/src/rescript/Utility/Declaration.res b/packages/squiggle-lang/src/rescript/Utility/Declaration.res new file mode 100644 index 00000000..188f01ca --- /dev/null +++ b/packages/squiggle-lang/src/rescript/Utility/Declaration.res @@ -0,0 +1,33 @@ +@genType +type continuousArg = Float({min: float, max: float}) | Time({min: Js.Date.t, max: Js.Date.t}) +@genType +type continuousDeclaration<'a> = {fn: 'a, args: array} +@genType +type relativeComparisonDeclaration<'a> = {fn: 'a, options: array} +@genType +type declaration<'a> = + Continuous(continuousDeclaration<'a>) | RelativeComparison(relativeComparisonDeclaration<'a>) + +module ContinuousFloatArg = { + let make = (min: float, max: float): continuousArg => { + Float({min: min, max: max}) + } +} + +module ContinuousTimeArg = { + let make = (min: Js.Date.t, max: Js.Date.t): continuousArg => { + Time({min: min, max: max}) + } +} + +module ContinuousDeclaration = { + let make = (fn: 'a, args: array): declaration<'a> => { + Continuous({fn: fn, args: args}) + } +} + +module RelativeComparisonDeclaration = { + let make = (fn: 'a, options: array): declaration<'a> => { + RelativeComparison({fn: fn, options: options}) + } +} From 533c97c41c5bc972010ec4dd434b3364f3c37005 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 24 May 2022 17:23:37 -0400 Subject: [PATCH 04/15] Added very simple lambdaDeclaration to React components --- .../src/components/SquiggleChart.tsx | 19 +++++++++++++++++++ packages/squiggle-lang/src/js/index.ts | 2 ++ .../squiggle-lang/src/js/rescript_interop.ts | 8 ++++++++ .../src/rescript/TypescriptInterface.res | 3 +++ 4 files changed, 32 insertions(+) diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 50fcebb3..1c5407c9 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -202,6 +202,25 @@ const SquiggleItem: React.FC = ({ ); } + case "lambdaDeclaration": { + switch (expression.value.tag) { + case "Continuous": { + return ( + + ); + } + case "RelativeComparison": { + return <>; + } + } + } case "lambda": return ( | tagged<"date", Date> | tagged<"timeDuration", number> + | tagged<"lambdaDeclaration", lambdaDeclaration> | tagged<"record", { [key: string]: squiggleExpression }>; export { lambdaValue }; @@ -141,6 +147,8 @@ export function convertRawToTypescript( return tag("date", result._0); case 11: // EvTimeDuration return tag("number", result._0); + case 12: // EvDeclaration + return tag("lambdaDeclaration", result._0); } } diff --git a/packages/squiggle-lang/src/rescript/TypescriptInterface.res b/packages/squiggle-lang/src/rescript/TypescriptInterface.res index 93af9832..44051cc1 100644 --- a/packages/squiggle-lang/src/rescript/TypescriptInterface.res +++ b/packages/squiggle-lang/src/rescript/TypescriptInterface.res @@ -76,6 +76,9 @@ let distributionErrorToString = DistributionTypes.Error.toString @genType type lambdaValue = ReducerInterface_ExpressionValue.lambdaValue +@genType +type lambdaDeclaration = ReducerInterface_ExpressionValue.lambdaDeclaration + @genType let defaultSamplingEnv = DistributionOperation.defaultEnv From c5673fd1b1b44bdba5a035996bc6022669699f5d Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 24 May 2022 19:14:13 -0400 Subject: [PATCH 05/15] Trying to add squigglechart types for declaration --- .../src/components/SquiggleChart.tsx | 22 +++++++++++++++++++ packages/squiggle-lang/src/js/index.ts | 3 +++ .../src/rescript/TypescriptInterface.res | 12 ++++++++++ 3 files changed, 37 insertions(+) diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 1c5407c9..6adfa5a6 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -11,12 +11,34 @@ import { defaultImports, defaultBindings, defaultEnvironment, + continuousDeclaration, + declarationContinuousArg, } from "@quri/squiggle-lang"; import { NumberShower } from "./NumberShower"; import { DistributionChart } from "./DistributionChart"; import { ErrorBox } from "./ErrorBox"; import { FunctionChart, FunctionChartSettings } from "./FunctionChart"; +function getRange(x: continuousDeclaration) { + let first = x.args[0] + switch(first.tag){ + case "Float": {return{floats: {min: first.value.min, max: first.value.max}}} + case "Time": {return{time: {min: first.value.min, max: first.value.max}}} + } +} +function getChartSettings(x: continuousDeclaration):FunctionChartSettings { + console.log("HERE") + let foo = getRange(x) + console.log("HIHI", foo) + let min = foo.floats ? foo.floats.min : 0 + let max = foo.floats ? foo.floats.max : 10 + return ({ + start: min, + stop: max, + count: 20, + }) +} + const variableBox = { Component: styled.div` background: white; diff --git a/packages/squiggle-lang/src/js/index.ts b/packages/squiggle-lang/src/js/index.ts index 3da19334..f06dac99 100644 --- a/packages/squiggle-lang/src/js/index.ts +++ b/packages/squiggle-lang/src/js/index.ts @@ -14,6 +14,9 @@ export { errorValueToString, distributionErrorToString, distributionError, + continuousDeclaration, + relativeComparisonDeclaration, + declarationContinuousArg, } from "../rescript/TypescriptInterface.gen"; export type { errorValue, externalBindings as bindings, jsImports }; import { diff --git a/packages/squiggle-lang/src/rescript/TypescriptInterface.res b/packages/squiggle-lang/src/rescript/TypescriptInterface.res index 44051cc1..e6170366 100644 --- a/packages/squiggle-lang/src/rescript/TypescriptInterface.res +++ b/packages/squiggle-lang/src/rescript/TypescriptInterface.res @@ -90,3 +90,15 @@ let defaultEnvironment = ReducerInterface_ExpressionValue.defaultEnvironment @genType let foreignFunctionInterface = Reducer.foreignFunctionInterface + +@genType +type declarationContinuousArg = Declaration.continuousArg + +@genType +type continuousDeclaration<'a> = Declaration.continuousDeclaration<'a> + +@genType +type relativeComparisonDeclaration<'a> = Declaration.relativeComparisonDeclaration<'a> + +@genType +type declaration<'a> = Declaration.declaration<'a> From 5d8f07c1b4098bbcddcad753e755576c8f88de51 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Wed, 25 May 2022 10:55:03 -0400 Subject: [PATCH 06/15] Minor fixes --- .../src/components/SquiggleChart.tsx | 33 +++++++++++-------- .../FunctionRegistry_Library.res | 3 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 6adfa5a6..092a2e2b 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -12,7 +12,6 @@ import { defaultBindings, defaultEnvironment, continuousDeclaration, - declarationContinuousArg, } from "@quri/squiggle-lang"; import { NumberShower } from "./NumberShower"; import { DistributionChart } from "./DistributionChart"; @@ -20,23 +19,29 @@ import { ErrorBox } from "./ErrorBox"; import { FunctionChart, FunctionChartSettings } from "./FunctionChart"; function getRange(x: continuousDeclaration) { - let first = x.args[0] - switch(first.tag){ - case "Float": {return{floats: {min: first.value.min, max: first.value.max}}} - case "Time": {return{time: {min: first.value.min, max: first.value.max}}} + let first = x.args[0]; + switch (first.tag) { + case "Float": { + return { floats: { min: first.value.min, max: first.value.max } }; + } + case "Time": { + return { time: { min: first.value.min, max: first.value.max } }; + } } } -function getChartSettings(x: continuousDeclaration):FunctionChartSettings { - console.log("HERE") - let foo = getRange(x) - console.log("HIHI", foo) - let min = foo.floats ? foo.floats.min : 0 - let max = foo.floats ? foo.floats.max : 10 - return ({ +function getChartSettings( + x: continuousDeclaration +): FunctionChartSettings { + console.log("HERE"); + let foo = getRange(x); + console.log("HIHI", foo); + let min = foo.floats ? foo.floats.min : 0; + let max = foo.floats ? foo.floats.max : 10; + return { start: min, stop: max, count: 20, - }) + }; } const variableBox = { @@ -230,7 +235,7 @@ const SquiggleItem: React.FC = ({ return ( + FnDefinition.make(~name="declareFn", ~inputs=[Declaration.frType], ~run=(inputs, _) => { inputs->E.A.unsafe_get(0)->Declaration.fromExpressionValue + } ), ], ), From 3404534b10da52cc1b2af604bfc1ad8f5afd7483 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Wed, 25 May 2022 13:11:35 -0400 Subject: [PATCH 07/15] Found some of the problem, will debug that next --- .../src/components/SquiggleChart.tsx | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 092a2e2b..1a3c4414 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -32,11 +32,9 @@ function getRange(x: continuousDeclaration) { function getChartSettings( x: continuousDeclaration ): FunctionChartSettings { - console.log("HERE"); - let foo = getRange(x); - console.log("HIHI", foo); - let min = foo.floats ? foo.floats.min : 0; - let max = foo.floats ? foo.floats.max : 10; + let range = getRange(x); + let min = range.floats ? range.floats.min : 0; + let max = range.floats ? range.floats.max : 10; return { start: min, stop: max, @@ -208,6 +206,7 @@ const SquiggleItem: React.FC = ({ /> ))} + ) ); case "arraystring": @@ -229,6 +228,17 @@ const SquiggleItem: React.FC = ({ ); } + case "lambda": + return ( + + ); case "lambdaDeclaration": { switch (expression.value.tag) { case "Continuous": { @@ -244,21 +254,16 @@ const SquiggleItem: React.FC = ({ ); } case "RelativeComparison": { - return <>; + return <>"Relative"; + } + default: { + return <>LambdaDeclaration: Should be unreachable; } } } - case "lambda": - return ( - - ); + default: { + return <>Should be unreachable; + } } }; From 298d3923bc096bf48622169cb49079e38807fc29 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Wed, 25 May 2022 19:27:15 -0400 Subject: [PATCH 08/15] Fixed bug caused by bad genType format of Declaration --- .../src/components/SquiggleChart.tsx | 21 +++------- packages/squiggle-lang/src/js/index.ts | 5 +-- .../squiggle-lang/src/js/rescript_interop.ts | 38 +++++++++++++++++-- .../FunctionRegistry_Core.res | 21 +++++----- .../FunctionRegistry_Library.res | 5 +-- .../src/rescript/TypescriptInterface.res | 8 +--- .../src/rescript/Utility/Declaration.res | 31 ++++++--------- 7 files changed, 68 insertions(+), 61 deletions(-) diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 1a3c4414..2971a3e1 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -11,14 +11,15 @@ import { defaultImports, defaultBindings, defaultEnvironment, - continuousDeclaration, + declarationArg, + declaration } from "@quri/squiggle-lang"; import { NumberShower } from "./NumberShower"; import { DistributionChart } from "./DistributionChart"; import { ErrorBox } from "./ErrorBox"; import { FunctionChart, FunctionChartSettings } from "./FunctionChart"; -function getRange(x: continuousDeclaration) { +function getRange(x: declaration) { let first = x.args[0]; switch (first.tag) { case "Float": { @@ -30,7 +31,7 @@ function getRange(x: continuousDeclaration) { } } function getChartSettings( - x: continuousDeclaration + x: declaration ): FunctionChartSettings { let range = getRange(x); let min = range.floats ? range.floats.min : 0; @@ -240,27 +241,17 @@ const SquiggleItem: React.FC = ({ /> ); case "lambdaDeclaration": { - switch (expression.value.tag) { - case "Continuous": { return ( ); - } - case "RelativeComparison": { - return <>"Relative"; - } - default: { - return <>LambdaDeclaration: Should be unreachable; - } } - } default: { return <>Should be unreachable; } diff --git a/packages/squiggle-lang/src/js/index.ts b/packages/squiggle-lang/src/js/index.ts index f06dac99..03068a51 100644 --- a/packages/squiggle-lang/src/js/index.ts +++ b/packages/squiggle-lang/src/js/index.ts @@ -14,9 +14,8 @@ export { errorValueToString, distributionErrorToString, distributionError, - continuousDeclaration, - relativeComparisonDeclaration, - declarationContinuousArg, + declarationArg, + declaration, } from "../rescript/TypescriptInterface.gen"; export type { errorValue, externalBindings as bindings, jsImports }; import { diff --git a/packages/squiggle-lang/src/js/rescript_interop.ts b/packages/squiggle-lang/src/js/rescript_interop.ts index 9d521927..64e7a64f 100644 --- a/packages/squiggle-lang/src/js/rescript_interop.ts +++ b/packages/squiggle-lang/src/js/rescript_interop.ts @@ -9,7 +9,8 @@ import { discreteShape, continuousShape, lambdaValue, - lambdaDeclaration + lambdaDeclaration, + declarationArg, } from "../rescript/TypescriptInterface.gen"; import { Distribution } from "./distribution"; import { tagged, tag } from "./types"; @@ -67,7 +68,7 @@ export type rescriptExport = } | { TAG: 12; // EvDeclaration - _0: lambdaDeclaration; + _0: rescriptLambdaDeclaration; }; type rescriptDist = @@ -89,6 +90,23 @@ type rescriptPointSetDist = _0: continuousShape; }; +type rescriptLambdaDeclaration = { + readonly fn: lambdaValue; + readonly args: rescriptDeclarationArg[]; +}; + +type rescriptDeclarationArg = + | { + TAG: 0; // Float + min: number; + max: number; + } + | { + TAG: 1; // Float + min: Date; + max: Date; + }; + export type squiggleExpression = | tagged<"symbol", string> | tagged<"string", string> @@ -148,7 +166,21 @@ export function convertRawToTypescript( case 11: // EvTimeDuration return tag("number", result._0); case 12: // EvDeclaration - return tag("lambdaDeclaration", result._0); + return tag("lambdaDeclaration", { + fn: result._0.fn, + args: result._0.args.map(convertDeclaration), + }); + } +} + +function convertDeclaration( + declarationArg: rescriptDeclarationArg +): declarationArg { + switch (declarationArg.TAG) { + case 0: // Float + return tag("Float", { min: declarationArg.min, max: declarationArg.max }); + case 1: // Date + return tag("Date", { min: declarationArg.min, max: declarationArg.max }); } } diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res index da5260c6..582df17d 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res @@ -78,9 +78,9 @@ module FRType = { | (FRTypeOption(v), _) => Some(FRValueOption(matchWithExpressionValue(v, r))) | (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)) - } + 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)) @@ -96,23 +96,24 @@ module FRType = { } let rec matchReverse = (e: frValue): expressionValue => - switch(e){ - | FRValueNumber(f) => (EvNumber(f)) + switch e { + | FRValueNumber(f) => EvNumber(f) | FRValueDistOrNumber(FRValueNumber(n)) => EvNumber(n) | FRValueDistOrNumber(FRValueDist(n)) => EvDistribution(n) | FRValueDist(dist) => EvDistribution(dist) | FRValueOption(Some(r)) => matchReverse(r) | FRValueArray(elements) => EvArray(elements->E.A2.fmap(matchReverse)) | FRValueRecord(frValueRecord) => { - let record = frValueRecord->E.A2.fmap(((name, value)) => (name, matchReverse(value)))->E.Dict.fromArray - EvRecord(record) - } + let record = + frValueRecord->E.A2.fmap(((name, value)) => (name, matchReverse(value)))->E.Dict.fromArray + EvRecord(record) + } | FRValueLambda(l) => EvLambda(l) | FRValueString(string) => EvString(string) | FRValueVariant(string) => EvString(string) - } + } - // | FRValueOption(None) => break + // | FRValueOption(None) => break let matchWithExpressionValueArray = (inputs: array, args: array): option< array, > => { diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res index 39f20d4d..54933d20 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res @@ -21,7 +21,7 @@ module Declaration = { ->E.A2.fmap(getMinMax) ->E.A.R.firstErrorOrOpen ->E.R2.fmap(args => ReducerInterface_ExpressionValue.EvDeclaration( - Declaration.ContinuousDeclaration.make(lambda, args), + Declaration.make(lambda, args), )) } | _ => Error("Error") @@ -35,8 +35,7 @@ let registry = [ ~definitions=[ FnDefinition.make(~name="declareFn", ~inputs=[Declaration.frType], ~run=(inputs, _) => { inputs->E.A.unsafe_get(0)->Declaration.fromExpressionValue - } - ), + }), ], ), Function.make( diff --git a/packages/squiggle-lang/src/rescript/TypescriptInterface.res b/packages/squiggle-lang/src/rescript/TypescriptInterface.res index e6170366..932edaa1 100644 --- a/packages/squiggle-lang/src/rescript/TypescriptInterface.res +++ b/packages/squiggle-lang/src/rescript/TypescriptInterface.res @@ -92,13 +92,7 @@ let defaultEnvironment = ReducerInterface_ExpressionValue.defaultEnvironment let foreignFunctionInterface = Reducer.foreignFunctionInterface @genType -type declarationContinuousArg = Declaration.continuousArg - -@genType -type continuousDeclaration<'a> = Declaration.continuousDeclaration<'a> - -@genType -type relativeComparisonDeclaration<'a> = Declaration.relativeComparisonDeclaration<'a> +type declarationArg = Declaration.arg @genType type declaration<'a> = Declaration.declaration<'a> diff --git a/packages/squiggle-lang/src/rescript/Utility/Declaration.res b/packages/squiggle-lang/src/rescript/Utility/Declaration.res index 188f01ca..d26e1833 100644 --- a/packages/squiggle-lang/src/rescript/Utility/Declaration.res +++ b/packages/squiggle-lang/src/rescript/Utility/Declaration.res @@ -1,33 +1,24 @@ @genType -type continuousArg = Float({min: float, max: float}) | Time({min: Js.Date.t, max: Js.Date.t}) +type arg = Float({min: float, max: float}) | Date({min: Js.Date.t, max: Js.Date.t}) + @genType -type continuousDeclaration<'a> = {fn: 'a, args: array} -@genType -type relativeComparisonDeclaration<'a> = {fn: 'a, options: array} -@genType -type declaration<'a> = - Continuous(continuousDeclaration<'a>) | RelativeComparison(relativeComparisonDeclaration<'a>) +type declaration<'a> = { + fn: 'a, + args: array, +} module ContinuousFloatArg = { - let make = (min: float, max: float): continuousArg => { + let make = (min: float, max: float): arg => { Float({min: min, max: max}) } } module ContinuousTimeArg = { - let make = (min: Js.Date.t, max: Js.Date.t): continuousArg => { - Time({min: min, max: max}) + let make = (min: Js.Date.t, max: Js.Date.t): arg => { + Date({min: min, max: max}) } } -module ContinuousDeclaration = { - let make = (fn: 'a, args: array): declaration<'a> => { - Continuous({fn: fn, args: args}) - } -} - -module RelativeComparisonDeclaration = { - let make = (fn: 'a, options: array): declaration<'a> => { - RelativeComparison({fn: fn, options: options}) - } +let make = (fn: 'a, args: array): declaration<'a> => { + {fn: fn, args: args} } From d630f7335dea257cda12b35d4355457a00b7c745 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Thu, 26 May 2022 08:23:43 -0400 Subject: [PATCH 09/15] Minor fixes --- .../src/components/SquiggleChart.tsx | 33 +++++++++---------- .../src/vega-specs/spec-percentiles.json | 1 + .../squiggle-lang/src/js/rescript_interop.ts | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 2971a3e1..31d48a1c 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -12,7 +12,7 @@ import { defaultBindings, defaultEnvironment, declarationArg, - declaration + declaration, } from "@quri/squiggle-lang"; import { NumberShower } from "./NumberShower"; import { DistributionChart } from "./DistributionChart"; @@ -25,14 +25,12 @@ function getRange(x: declaration) { case "Float": { return { floats: { min: first.value.min, max: first.value.max } }; } - case "Time": { - return { time: { min: first.value.min, max: first.value.max } }; + case "Date": { + return { time: { min: first.value.min, max: first.value.max} }; } } } -function getChartSettings( - x: declaration -): FunctionChartSettings { +function getChartSettings(x: declaration): FunctionChartSettings { let range = getRange(x); let min = range.floats ? range.floats.min : 0; let max = range.floats ? range.floats.max : 10; @@ -207,7 +205,6 @@ const SquiggleItem: React.FC = ({ /> ))} - ) ); case "arraystring": @@ -241,17 +238,17 @@ const SquiggleItem: React.FC = ({ /> ); case "lambdaDeclaration": { - return ( - - ); - } + return ( + + ); + } default: { return <>Should be unreachable; } diff --git a/packages/components/src/vega-specs/spec-percentiles.json b/packages/components/src/vega-specs/spec-percentiles.json index d533a866..36e4450c 100644 --- a/packages/components/src/vega-specs/spec-percentiles.json +++ b/packages/components/src/vega-specs/spec-percentiles.json @@ -75,6 +75,7 @@ "name": "xscale", "type": "linear", "nice": true, + "zero": false, "domain": { "data": "facet", "field": "x" diff --git a/packages/squiggle-lang/src/js/rescript_interop.ts b/packages/squiggle-lang/src/js/rescript_interop.ts index 64e7a64f..9f9bdb39 100644 --- a/packages/squiggle-lang/src/js/rescript_interop.ts +++ b/packages/squiggle-lang/src/js/rescript_interop.ts @@ -102,7 +102,7 @@ type rescriptDeclarationArg = max: number; } | { - TAG: 1; // Float + TAG: 1; // Date min: Date; max: Date; }; From 554e50901e8e313585b7c7bb9bdb2c27f2b5b42a Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Thu, 26 May 2022 08:30:37 -0400 Subject: [PATCH 10/15] Added VariableBox for functiona and function declaration --- packages/components/src/components/SquiggleChart.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 31d48a1c..4479013e 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -228,6 +228,7 @@ const SquiggleItem: React.FC = ({ } case "lambda": return ( + = ({ xyPointLength: environment.xyPointLength / 10, }} /> + ); case "lambdaDeclaration": { return ( + = ({ xyPointLength: environment.xyPointLength / 10, }} /> + ); } default: { From cbc51c23de28e7a356bfee01484be9efc6ce3b8d Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 27 May 2022 07:29:39 -0400 Subject: [PATCH 11/15] Minor improvement of error type --- .../src/rescript/FunctionRegistry/FunctionRegistry_Library.res | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res index 54933d20..532f534d 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res @@ -24,7 +24,8 @@ module Declaration = { Declaration.make(lambda, args), )) } - | _ => Error("Error") + | Error(r) => Error(r) + | Ok(_) => Error(FunctionRegistry_Helpers.impossibleError) } } } From 4eac2f59beed9855ee8121a0aa34618549acc8ff Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 27 May 2022 07:32:03 -0400 Subject: [PATCH 12/15] Ran formatter --- .../src/components/SquiggleChart.tsx | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 4479013e..bb166682 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -26,7 +26,7 @@ function getRange(x: declaration) { return { floats: { min: first.value.min, max: first.value.max } }; } case "Date": { - return { time: { min: first.value.min, max: first.value.max} }; + return { time: { min: first.value.min, max: first.value.max } }; } } } @@ -229,27 +229,27 @@ const SquiggleItem: React.FC = ({ case "lambda": return ( - + ); case "lambdaDeclaration": { return ( - + ); } From 529a8a6763491acc7bed7d5e4dccfdb101579bae Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 27 May 2022 07:44:55 -0400 Subject: [PATCH 13/15] Ran yarn --- yarn.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/yarn.lock b/yarn.lock index 680465a1..f5044f7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4310,10 +4310,10 @@ dependencies: "@types/react" "*" -"@types/react@*", "@types/react@17.0.43", "@types/react@^18.0.9": - version "17.0.43" - resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.43.tgz#4adc142887dd4a2601ce730bc56c3436fdb07a55" - integrity sha512-8Q+LNpdxf057brvPu1lMtC5Vn7J119xrP1aq4qiaefNioQUYANF/CYeK4NsKorSZyUGJ66g0IM+4bbjwx45o2A== +"@types/react@*", "@types/react@^18.0.1", "@types/react@^18.0.9": + version "18.0.9" + resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.9.tgz#d6712a38bd6cd83469603e7359511126f122e878" + integrity sha512-9bjbg1hJHUm4De19L1cHiW0Jvx3geel6Qczhjd0qY5VKVE2X5+x77YxAepuCwVh4vrgZJdgEJw48zrhRIeF4Nw== dependencies: "@types/prop-types" "*" "@types/scheduler" "*" @@ -14557,7 +14557,7 @@ react-vega@^7.5.1: prop-types "^15.8.1" vega-embed "^6.5.1" -react@^18.1.0: +react@^18.0.0, react@^18.1.0: version "18.1.0" resolved "https://registry.yarnpkg.com/react/-/react-18.1.0.tgz#6f8620382decb17fdc5cc223a115e2adbf104890" integrity sha512-4oL8ivCz5ZEPyclFQXaNksK3adutVS8l2xzZU0cqEFrE9Sb7fC0EFK5uEk74wIreL1DERyjvsU915j1pcT2uEQ== From 20f901e3f863545d45d6ab1646a32ce00c712cb1 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 27 May 2022 07:58:43 -0400 Subject: [PATCH 14/15] Added Declaration toString --- .../FunctionRegistry/FunctionRegistry_Core.res | 6 ------ .../ReducerInterface_ExpressionValue.res | 5 ++++- .../src/rescript/Utility/Declaration.res | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res index 582df17d..eed48ffc 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Core.res @@ -11,7 +11,6 @@ type rec frType = | FRTypeLambda | FRTypeRecord(frTypeRecord) | FRTypeArray(frType) - | FRTypeOption(frType) | FRTypeString | FRTypeVariant(array) and frTypeRecord = array @@ -24,7 +23,6 @@ and frTypeRecordParam = (string, frType) type rec frValue = | FRValueNumber(float) | FRValueDist(DistributionTypes.genericDist) - | FRValueOption(option) | FRValueArray(array) | FRValueDistOrNumber(frValueDistOrNumber) | FRValueRecord(frValueRecord) @@ -60,7 +58,6 @@ module FRType = { `record({${r->E.A2.fmap(input)->E.A2.joinWith(", ")}})` } | FRTypeArray(r) => `record(${toString(r)})` - | FRTypeOption(v) => `option(${toString(v)})` | FRTypeLambda => `lambda` | FRTypeString => `string` | FRTypeVariant(_) => "variant" @@ -75,7 +72,6 @@ module FRType = { | (FRTypeDistOrNumber, EvDistribution(f)) => Some(FRValueDistOrNumber(FRValueDist(f))) | (FRTypeNumeric, EvNumber(f)) => Some(FRValueNumber(f)) | (FRTypeNumeric, EvDistribution(Symbolic(#Float(f)))) => Some(FRValueNumber(f)) - | (FRTypeOption(v), _) => Some(FRValueOption(matchWithExpressionValue(v, r))) | (FRTypeLambda, EvLambda(f)) => Some(FRValueLambda(f)) | (FRTypeArray(intendedType), EvArray(elements)) => { let el = elements->E.A2.fmap(matchWithExpressionValue(intendedType)) @@ -101,7 +97,6 @@ module FRType = { | FRValueDistOrNumber(FRValueNumber(n)) => EvNumber(n) | FRValueDistOrNumber(FRValueDist(n)) => EvDistribution(n) | FRValueDist(dist) => EvDistribution(dist) - | FRValueOption(Some(r)) => matchReverse(r) | FRValueArray(elements) => EvArray(elements->E.A2.fmap(matchReverse)) | FRValueRecord(frValueRecord) => { let record = @@ -113,7 +108,6 @@ module FRType = { | FRValueVariant(string) => EvString(string) } - // | FRValueOption(None) => break let matchWithExpressionValueArray = (inputs: array, args: array): option< array, > => { diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res index 8f3dea42..aa040fc2 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res @@ -57,7 +57,7 @@ let rec toString = aValue => | EvDistribution(dist) => GenericDist.toString(dist) | EvDate(date) => DateTime.Date.toString(date) | EvTimeDuration(t) => DateTime.Duration.toString(t) - | EvDeclaration(t) => "Declaration" + | EvDeclaration(d) => Declaration.toString(d, r => toString(EvLambda(r))) } and toStringRecord = aRecord => { let pairs = @@ -128,6 +128,7 @@ type expressionValueType = | EvtSymbol | EvtDate | EvtTimeDuration + | EvtDeclaration type functionCallSignature = CallSignature(string, array) type functionDefinitionSignature = @@ -147,6 +148,7 @@ let valueToValueType = value => | EvSymbol(_) => EvtSymbol | EvDate(_) => EvtDate | EvTimeDuration(_) => EvtTimeDuration + | EvDeclaration(_) => EvtDeclaration } let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => { @@ -168,6 +170,7 @@ let valueTypeToString = (valueType: expressionValueType): string => | EvtSymbol => `Symbol` | EvtDate => `Date` | EvtTimeDuration => `Duration` + | EvtDeclaration => `Declaration` } let functionCallSignatureToString = (functionCallSignature: functionCallSignature): string => { diff --git a/packages/squiggle-lang/src/rescript/Utility/Declaration.res b/packages/squiggle-lang/src/rescript/Utility/Declaration.res index d26e1833..871dd580 100644 --- a/packages/squiggle-lang/src/rescript/Utility/Declaration.res +++ b/packages/squiggle-lang/src/rescript/Utility/Declaration.res @@ -19,6 +19,24 @@ module ContinuousTimeArg = { } } +module Arg = { + let toString = (arg: arg) => { + switch arg { + | Float({min, max}) => + `Float({min: ${E.Float.with2DigitsPrecision(min)}, max: ${E.Float.with2DigitsPrecision( + max, + )}})` + | Date({min, max}) => + `Date({min: ${DateTime.Date.toString(min)}, max: ${DateTime.Date.toString(max)}})` + } + } +} + let make = (fn: 'a, args: array): declaration<'a> => { {fn: fn, args: args} } + +let toString = (r: declaration<'a>, fnToString): string => { + let args = r.args->E.A2.fmap(Arg.toString) |> E.A.joinWith(", ") + return`fn: ${fnToString(r.fn)}, args: [${args}]` +} From d0102ae4f2acdcf7b6f8ff8ecd54d4a6c7e45f10 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 27 May 2022 08:26:10 -0400 Subject: [PATCH 15/15] Changed graph axis to use .9-s format --- packages/components/src/vega-specs/spec-distributions.json | 2 +- packages/components/src/vega-specs/spec-line-chart.json | 5 ++++- packages/components/src/vega-specs/spec-percentiles.json | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/components/src/vega-specs/spec-distributions.json b/packages/components/src/vega-specs/spec-distributions.json index 29ca4e1d..cb3db4b8 100644 --- a/packages/components/src/vega-specs/spec-distributions.json +++ b/packages/components/src/vega-specs/spec-distributions.json @@ -23,7 +23,7 @@ "tickOpacity": 0.0, "domainColor": "#fff", "domainOpacity": 0.0, - "format": "~g", + "format": ".9~s", "tickCount": 10 } ], diff --git a/packages/components/src/vega-specs/spec-line-chart.json b/packages/components/src/vega-specs/spec-line-chart.json index 117d9543..6180ad76 100644 --- a/packages/components/src/vega-specs/spec-line-chart.json +++ b/packages/components/src/vega-specs/spec-line-chart.json @@ -20,6 +20,7 @@ "name": "x", "type": "linear", "nice": true, + "zero": false, "domain": { "data": "facet", "field": "x" @@ -31,7 +32,7 @@ "type": "linear", "range": "height", "nice": true, - "zero": true, + "zero": false, "domain": { "data": "facet", "field": "y" @@ -58,6 +59,7 @@ "tickOpacity": 0.0, "domainColor": "#727d93", "domainOpacity": 0.1, + "format": ".9~s", "tickCount": 5 }, { @@ -69,6 +71,7 @@ "tickOpacity": 0.0, "domainColor": "#727d93", "domainOpacity": 0.1, + "format": ".9~s", "tickCount": 5 } ], diff --git a/packages/components/src/vega-specs/spec-percentiles.json b/packages/components/src/vega-specs/spec-percentiles.json index 36e4450c..415cc173 100644 --- a/packages/components/src/vega-specs/spec-percentiles.json +++ b/packages/components/src/vega-specs/spec-percentiles.json @@ -87,10 +87,10 @@ "type": "linear", "range": "height", "nice": true, - "zero": true, + "zero": false, "domain": { "data": "facet", - "field": "p99" + "fields": ["p1", "p99"] } } ], @@ -114,12 +114,14 @@ "tickOpacity": 0.0, "domainColor": "#727d93", "domainOpacity": 0.1, + "format": ".9~s", "tickCount": 5 }, { "orient": "left", "scale": "yscale", "grid": false, + "format": ".9~s", "labelColor": "#727d93", "tickColor": "#fff", "tickOpacity": 0.0,