From 4522b46900b48ecbb9c9cf086a40eb8efecccbd5 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Fri, 15 Jul 2022 23:18:39 +0200 Subject: [PATCH 01/19] basic type compiler --- .../Reducer_Type_Compile_test.res | 62 +++++++++++++++++++ .../Reducer_Dispatch_BuiltIn.res | 2 +- .../rescript/Reducer/Reducer_Exception.res | 4 +- .../Reducer_Type/Reducer_Type_Compile.res | 36 +++++++++++ .../Reducer/Reducer_Type/Reducer_Type_T.res | 54 +++++++++++++--- .../Reducer_Type/Reducer_Type_TypeBuilder.res | 16 ++--- .../Reducer_Type/Reducer_Type_TypeChecker.res | 30 +++------ 7 files changed, 160 insertions(+), 44 deletions(-) create mode 100644 packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res create mode 100644 packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res new file mode 100644 index 00000000..3f97ca3f --- /dev/null +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res @@ -0,0 +1,62 @@ +module Expression = Reducer_Expression +module InternalExpressionValue = ReducerInterface_InternalExpressionValue +module Module = Reducer_Module +module T = Reducer_Type_T +module TypeCompile = Reducer_Type_Compile + +open Jest +open Expect + +let myIevEval = (aTypeSourceCode: string) => + TypeCompile.ievFromTypeExpression(aTypeSourceCode, Expression.reduceExpression) +let myIevEvalToString = (aTypeSourceCode: string) => + myIevEval(aTypeSourceCode)->InternalExpressionValue.toStringResult + +let myIevExpectEqual = (aTypeSourceCode, answer) => + expect(myIevEvalToString(aTypeSourceCode))->toEqual(answer) + +let _myIevTest = (test, aTypeSourceCode, answer) => + test(aTypeSourceCode, () => myIevExpectEqual(aTypeSourceCode, answer)) + +let myTypeEval = (aTypeSourceCode: string) => + TypeCompile.fromTypeExpression(aTypeSourceCode, Expression.reduceExpression) +let myTypeEvalToString = (aTypeSourceCode: string) => myTypeEval(aTypeSourceCode)->T.toStringResult + +let myTypeExpectEqual = (aTypeSourceCode, answer) => + expect(myTypeEvalToString(aTypeSourceCode))->toEqual(answer) + +let _myTypeTest = (test, aTypeSourceCode, answer) => + test(aTypeSourceCode, () => myTypeExpectEqual(aTypeSourceCode, answer)) + +let myIevTest = (aTypeSourceCode, answer) => _myIevTest(test, aTypeSourceCode, answer) +let myTypeTest = (aTypeSourceCode, answer) => _myTypeTest(test, aTypeSourceCode, answer) +module MySkip = { + let myIevTest = (aTypeSourceCode, answer) => _myIevTest(Skip.test, aTypeSourceCode, answer) + let myTypeTest = (aTypeSourceCode, answer) => _myTypeTest(Skip.test, aTypeSourceCode, answer) +} +module MyOnly = { + let myIevTest = (aTypeSourceCode, answer) => _myIevTest(Only.test, aTypeSourceCode, answer) + let myTypeTest = (aTypeSourceCode, answer) => _myTypeTest(Only.test, aTypeSourceCode, answer) +} + +// | ItTypeIdentifier(string) +myTypeTest("number", "number") +myTypeTest("(number)", "number") +// | ItModifiedType({modifiedType: iType}) +myIevTest("number<-min(0)", "Ok({min: 0,typeIdentifier: #number,typeTag: 'typeIdentifier'})") +myTypeTest("number<-min(0)", "number<-min(0)") +// | ItTypeOr({typeOr: array}) +myTypeTest("number | string", "(number | string)") +// | ItTypeFunction({inputs: array, output: iType}) +myTypeTest("number => number => number", "(number => number => number)") +// | ItTypeArray({element: iType}) +myIevTest("[number]", "Ok({element: #number,typeTag: 'typeArray'})") +myTypeTest("[number]", "[number]") +// | ItTypeTuple({elements: array}) +myTypeTest("[number, string]", "[number, string]") +// | ItTypeRecord({properties: Belt.Map.String.t}) +myIevTest( + "{age: number, name: string}", + "Ok({properties: {age: #number,name: #string},typeTag: 'typeRecord'})", +) +myTypeTest("{age: number, name: string}", "{age: number, name: string}") diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res index 484b0acb..07766aca 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res @@ -198,7 +198,7 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce | ("$_typeFunction_$", [IEvArray(arr)]) => TypeBuilder.typeFunction(arr) | ("$_typeTuple_$", [IEvArray(elems)]) => TypeBuilder.typeTuple(elems) | ("$_typeArray_$", [elem]) => TypeBuilder.typeArray(elem) - | ("$_typeRecord_$", [IEvArray(arrayOfPairs)]) => TypeBuilder.typeRecord(arrayOfPairs) + | ("$_typeRecord_$", [IEvRecord(propertyMap)]) => TypeBuilder.typeRecord(propertyMap) | ("concat", [IEvArray(aValueArray), IEvArray(bValueArray)]) => doAddArray(aValueArray, bValueArray) | ("concat", [IEvString(aValueString), IEvString(bValueString)]) => diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Exception.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Exception.res index d7ca335c..14db0843 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Exception.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Exception.res @@ -1,3 +1,3 @@ -// There are switch stament cases in the code which are impossible to reach by design. +// There are switch statement cases in the code which are impossible to reach by design. // ImpossibleException is a sign of programming error. -exception ImpossibleException +exception ImpossibleException(string) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res new file mode 100644 index 00000000..c7a776b7 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res @@ -0,0 +1,36 @@ +module ErrorValue = Reducer_ErrorValue +module ExpressionT = Reducer_Expression_T +module InternalExpressionValue = ReducerInterface_InternalExpressionValue +module Module = Reducer_Module +module T = Reducer_Type_T + +let ievFromTypeExpression = ( + typeExpressionSourceCode: string, + reducerFn: ExpressionT.reducerFn, +): result => { + let sIndex = "compiled" + let sourceCode = `type ${sIndex}=${typeExpressionSourceCode}` + Reducer_Expression.parse(sourceCode)->Belt.Result.flatMap(expr => { + let rContext = reducerFn(expr, Module.emptyBindings, InternalExpressionValue.defaultEnvironment) + Belt.Result.map(rContext, context => + switch context { + | IEvModule(nameSpace) => + switch Module.getType(nameSpace, sIndex) { + | Some(value) => value + | None => raise(Reducer_Exception.ImpossibleException("Reducer_Type_Compile-none")) + } + | _ => raise(Reducer_Exception.ImpossibleException("Reducer_Type_Compile-raise")) + } + ) + }) +} + +let fromTypeExpression = ( + typeExpressionSourceCode: string, + reducerFn: ExpressionT.reducerFn, +): result => { + ievFromTypeExpression( + (typeExpressionSourceCode: string), + (reducerFn: ExpressionT.reducerFn), + )->Belt.Result.map(T.fromIEvValue) +} diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res index 9b847ca7..0e3b240d 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res @@ -3,13 +3,41 @@ open InternalExpressionValue type rec iType = | ItTypeIdentifier(string) - | ItModifiedType({modifiedType: iType}) + | ItModifiedType({modifiedType: iType, modifiers: Belt.Map.String.t}) | ItTypeOr({typeOr: array}) | ItTypeFunction({inputs: array, output: iType}) | ItTypeArray({element: iType}) | ItTypeTuple({elements: array}) | ItTypeRecord({properties: Belt.Map.String.t}) +type t = iType + +let rec toString = (t: t): string => { + switch t { + | ItTypeIdentifier(s) => s + | ItModifiedType({modifiedType, modifiers}) => + `${toString(modifiedType)}${modifiers->Belt.Map.String.reduce("", (acc, k, v) => + Js.String2.concatMany(acc, ["<-", k, "(", InternalExpressionValue.toString(v), ")"]) + )}` + | ItTypeOr({typeOr}) => `(${Js.Array2.map(typeOr, toString)->Js.Array2.joinWith(" | ")})` + | ItTypeFunction({inputs, output}) => + `(${inputs->Js.Array2.map(toString)->Js.Array2.joinWith(" => ")} => ${toString(output)})` + | ItTypeArray({element}) => `[${toString(element)}]` + | ItTypeTuple({elements}) => `[${Js.Array2.map(elements, toString)->Js.Array2.joinWith(", ")}]` + | ItTypeRecord({properties}) => + `{${properties + ->Belt.Map.String.toArray + ->Js.Array2.map(((k, v)) => Js.String2.concatMany(k, [": ", toString(v)])) + ->Js.Array2.joinWith(", ")}}` + } +} + +let toStringResult = (rt: result) => + switch rt { + | Ok(t) => toString(t) + | Error(e) => ErrorValue.errorToString(e) + } + let rec fromTypeMap = typeMap => { let default = IEvString("") let evTypeTag: InternalExpressionValue.t = Belt.Map.String.getWithDefault( @@ -52,31 +80,39 @@ let rec fromTypeMap = typeMap => { "properties", default, ) - //TODO: map type modifiers - switch evTypeTag { - | IEvString("typeIdentifier") => ItModifiedType({modifiedType: fromIEvValue(evTypeIdentifier)}) + + let modifiers = + typeMap->Belt.Map.String.keep((k, _v) => ["min", "max", "memberOf"]->Js.Array2.includes(k)) + + let makeIt = switch evTypeTag { + | IEvString("typeIdentifier") => fromIEvValue(evTypeIdentifier) | IEvString("typeOr") => ItTypeOr({typeOr: fromIEvArray(evTypeOr)}) | IEvString("typeFunction") => ItTypeFunction({inputs: fromIEvArray(evInputs), output: fromIEvValue(evOutput)}) | IEvString("typeArray") => ItTypeArray({element: fromIEvValue(evElement)}) | IEvString("typeTuple") => ItTypeTuple({elements: fromIEvArray(evElements)}) | IEvString("typeRecord") => ItTypeRecord({properties: fromIEvRecord(evProperties)}) - | _ => raise(Reducer_Exception.ImpossibleException) + | _ => raise(Reducer_Exception.ImpossibleException("Reducer_Type_T-evTypeTag")) } + + Belt.Map.String.isEmpty(modifiers) + ? makeIt + : ItModifiedType({modifiedType: makeIt, modifiers: modifiers}) } -and fromIEvValue = (ievValue: InternalExpressionValue.t) => + +and fromIEvValue = (ievValue: InternalExpressionValue.t): iType => switch ievValue { | IEvTypeIdentifier(typeIdentifier) => ItTypeIdentifier({typeIdentifier}) | IEvType(typeMap) => fromTypeMap(typeMap) - | _ => raise(Reducer_Exception.ImpossibleException) + | _ => raise(Reducer_Exception.ImpossibleException("Reducer_Type_T-ievValue")) } and fromIEvArray = (ievArray: InternalExpressionValue.t) => switch ievArray { | IEvArray(array) => array->Belt.Array.map(fromIEvValue) - | _ => raise(Reducer_Exception.ImpossibleException) + | _ => raise(Reducer_Exception.ImpossibleException("Reducer_Type_T-ievArray")) } and fromIEvRecord = (ievRecord: InternalExpressionValue.t) => switch ievRecord { | IEvRecord(record) => record->Belt.Map.String.map(fromIEvValue) - | _ => raise(Reducer_Exception.ImpossibleException) + | _ => raise(Reducer_Exception.ImpossibleException("Reducer_Type_T-ievRecord")) } diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeBuilder.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeBuilder.res index e51f901a..d3906a38 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeBuilder.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeBuilder.res @@ -56,7 +56,7 @@ let typeFunction = anArray => { let typeArray = element => { let newRecord = Belt.Map.String.fromArray([ - ("typeTag", IEvString("typeTuple")), + ("typeTag", IEvString("typeArray")), ("element", element), ]) newRecord->IEvType->Ok @@ -64,22 +64,14 @@ let typeArray = element => { let typeTuple = anArray => { let newRecord = Belt.Map.String.fromArray([ - ("typeTag", IEvString("typeArray")), + ("typeTag", IEvString("typeTuple")), ("elements", IEvArray(anArray)), ]) newRecord->IEvType->Ok } -let typeRecord = arrayOfPairs => { - let newProperties = - Belt.Array.map(arrayOfPairs, pairValue => - switch pairValue { - | IEvArray([IEvString(key), valueValue]) => (key, valueValue) - | _ => ("wrong key type", pairValue->toStringWithType->IEvString) - } - ) - ->Belt.Map.String.fromArray - ->IEvRecord +let typeRecord = propertyMap => { + let newProperties = propertyMap->IEvRecord let newRecord = Belt.Map.String.fromArray([ ("typeTag", IEvString("typeRecord")), ("properties", newProperties), diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res index 18cb804a..a1a6bdc2 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res @@ -1,13 +1,10 @@ -module ExpressionT = Reducer_Expression_T +// module ErrorValue = Reducer_ErrorValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue module T = Reducer_Type_T -module TypeBuilder = Reducer_Type_TypeBuilder +// module TypeBuilder = Reducer_Type_TypeBuilder open InternalExpressionValue -type typeErrorValue = - | TypeError(T.iType, InternalExpressionValue.t) - | TypeErrorWithPosition(T.iType, InternalExpressionValue.t, int) - | TypeErrorWithProperty(T.iType, InternalExpressionValue.t, string) +type typeErrorValue = TypeError(T.t, InternalExpressionValue.t) let rec isOfResolvedIType = (anIType: T.iType, aValue): result => { let caseTypeIdentifier = (anUpperTypeName, aValue) => { @@ -24,16 +21,16 @@ let rec isOfResolvedIType = (anIType: T.iType, aValue): result switch Belt.Map.String.get(map, property) { | Some(propertyValue) => isOfResolvedIType(propertyType, propertyValue) - | None => TypeErrorWithProperty(anIType, evValue, property)->Error + | None => TypeError(anIType, evValue)->Error } ) }) } let _caseArray = (anIType, evValue, elementType, anArray) => { - Belt.Array.reduceWithIndex(anArray, Ok(true), (acc, element, index) => { + Belt.Array.reduceWithIndex(anArray, Ok(true), (acc, element, _index) => { switch isOfResolvedIType(elementType, element) { | Ok(_) => acc - | Error(_) => TypeErrorWithPosition(anIType, evValue, index)->Error + | Error(_) => TypeError(anIType, evValue)->Error } }) } @@ -48,12 +45,12 @@ let rec isOfResolvedIType = (anIType: T.iType, aValue): result raise(Reducer_Exception.ImpossibleException) // | ItTypeTuple({elements: anITypeArray}) => raise(Reducer_Exception.ImpossibleException) // | ItTypeRecord({properties: anITypeMap}) => raise(Reducer_Exception.ImpossibleException) - | _ => raise(Reducer_Exception.ImpossibleException) + | _ => raise(Reducer_Exception.ImpossibleException("Reducer_TypeChecker-isOfResolvedIType")) } } -let isOfResolvedType = (aType: InternalExpressionValue.t, aValue): result => - aType->T.fromIEvValue->isOfResolvedIType(aValue) +// let isOfResolvedType = (aType: InternalExpressionValue.t, aValue): result => +// aType->T.fromIEvValue->isOfResolvedIType(aValue) // TODO: Work in progress. Code is commented to make an a release of other features // let checkArguments = ( @@ -70,12 +67,5 @@ let isOfResolvedType = (aType: InternalExpressionValue.t, aValue): result raise(Reducer_Exception.ImpossibleException) // } // let rTupleType = TypeBuilder.typeTuple(inputs) -// Belt.Result.flatMap(rTupleType, tuppleType => isOfResolvedType(tuppleType, args->IEvArray)) +// Belt.Result.flatMap(rTupleType, tupleType => isOfResolvedType(tupleType, args->IEvArray)) // } - -// let compileTypeExpression = (typeExpression: string, bindings: ExpressionT.bindings, reducerFn: ExpressionT.reducerFn) => { -// statement = `type compiled=${typeExpression}` - -// } - -//TODO: asGuard From b65aeaf0d2c59f7f855d67d588ff645e8b108412 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Sat, 16 Jul 2022 17:08:23 +0200 Subject: [PATCH 02/19] spell check --- .../Reducer/Reducer_Peggy/Reducer_Peggy_Parse_type_test.res | 4 ++-- .../Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res | 2 +- .../Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res | 4 ++-- .../Reducer/Reducer_Expression/Reducer_Expression_T.res | 4 ++-- .../rescript/Reducer/Reducer_Extra/Reducer_Extra_Array.res | 4 ++-- .../src/rescript/Reducer/Reducer_Extra/Reducer_Extra_List.res | 4 ++-- .../rescript/Reducer/Reducer_Peggy/Reducer_Peggy_Parse.res | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_type_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_type_test.res index ea18effc..f1dcd4bc 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_type_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_type_test.res @@ -63,8 +63,8 @@ describe("Peggy parse type", () => { "{(::$_typeOf_$ :weekend (::$_typeOr_$ (::$_constructArray_$ ((::$_typeConstructor_$ #Saturday (::$_constructArray_$ ())) (::$_typeConstructor_$ #Sunday (::$_constructArray_$ ()))))))}", ) }) - describe("type paranthesis", () => { - //$ is introduced to avoid paranthesis + describe("type parenthesis", () => { + //$ is introduced to avoid parenthesis testParse( "answer: (number|string)<-opaque", "{(::$_typeOf_$ :answer (::$_typeModifier_opaque_$ (::$_typeOr_$ (::$_constructArray_$ (#number #string)))))}", diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res index 18e8121d..d0609d09 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res @@ -3,7 +3,7 @@ open Reducer_Peggy_TestHelpers describe("Peggy to Expression", () => { describe("literals operators parenthesis", () => { - // Note that there is always an outer block. Otherwise, external bindings are ignrored at the first statement + // Note that there is always an outer block. Otherwise, external bindings are ignored at the first statement testToExpression("1", "{1}", ~v="1", ()) testToExpression("'hello'", "{'hello'}", ~v="'hello'", ()) testToExpression("true", "{true}", ~v="true", ()) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res index 07766aca..0e8a479e 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res @@ -10,8 +10,8 @@ open ReducerInterface_InternalExpressionValue open Reducer_ErrorValue /* - MathJs provides default implementations for builtins - This is where all the expected builtins like + = * / sin cos log ln etc are handled + MathJs provides default implementations for built-ins + This is where all the expected built-ins like + = * / sin cos log ln etc are handled DO NOT try to add external function mapping here! */ diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression_T.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression_T.res index bf4d0170..c9739be3 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression_T.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression_T.res @@ -30,12 +30,12 @@ let rec toString = expression => switch expression { | EList(list{EValue(IEvCall("$$_block_$$")), ...statements}) => `{${Belt.List.map(statements, aValue => toString(aValue)) - ->Extra.List.interperse("; ") + ->Extra.List.intersperse("; ") ->Belt.List.toArray ->Js.String.concatMany("")}}` | EList(aList) => `(${Belt.List.map(aList, aValue => toString(aValue)) - ->Extra.List.interperse(" ") + ->Extra.List.intersperse(" ") ->Belt.List.toArray ->Js.String.concatMany("")})` | EValue(aValue) => InternalExpressionValue.toString(aValue) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Extra/Reducer_Extra_Array.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Extra/Reducer_Extra_Array.res index 58dd4ffd..8c9f2fbb 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Extra/Reducer_Extra_Array.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Extra/Reducer_Extra_Array.res @@ -3,5 +3,5 @@ */ module ExtraList = Reducer_Extra_List -let interperse = (anArray, seperator) => - anArray->Belt.List.fromArray->ExtraList.interperse(seperator)->Belt.List.toArray +let intersperse = (anArray, seperator) => + anArray->Belt.List.fromArray->ExtraList.intersperse(seperator)->Belt.List.toArray diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Extra/Reducer_Extra_List.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Extra/Reducer_Extra_List.res index 9b3bcc3d..b723cca4 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Extra/Reducer_Extra_List.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Extra/Reducer_Extra_List.res @@ -1,9 +1,9 @@ /* Insert seperator between the elements of a list */ -let rec interperse = (aList, seperator) => +let rec intersperse = (aList, seperator) => switch aList { | list{} => list{} | list{a} => list{a} - | list{a, ...rest} => list{a, seperator, ...interperse(rest, seperator)} + | list{a, ...rest} => list{a, seperator, ...intersperse(rest, seperator)} } diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_Parse.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_Parse.res index 67873c61..a38c66e9 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_Parse.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_Parse.res @@ -91,7 +91,7 @@ let rec pgToString = (peggyNode: peggyNode): string => { args->Js.Array2.map(arg => PgNodeIdentifier(arg)->pgToString)->Js.Array2.toString let nodesToStringUsingSeparator = (nodes: array, separator: string): string => - nodes->Js.Array2.map(toString)->Extra.Array.interperse(separator)->Js.String.concatMany("") + nodes->Js.Array2.map(toString)->Extra.Array.intersperse(separator)->Js.String.concatMany("") switch peggyNode { | PgNodeBlock(node) => "{" ++ node["statements"]->nodesToStringUsingSeparator("; ") ++ "}" From 8fb75d57fc2b3617b7b2fa8ecdfed117698b9d7e Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 18 Jul 2022 10:27:41 +0200 Subject: [PATCH 03/19] type check --- ...educer_Type_TypeChecker_arguments_test.res | 52 +++++ .../Reducer_Type_TypeChecker_test.res | 78 +++++++ .../Reducer_Dispatch_BuiltInMacros.res | 2 +- .../rescript/Reducer/Reducer_ErrorValue.res | 4 +- .../Reducer_Type/Reducer_Type_Modifiers.res | 53 +++++ .../Reducer/Reducer_Type/Reducer_Type_T.res | 1 + .../Reducer_Type/Reducer_Type_TypeChecker.res | 191 +++++++++++++----- 7 files changed, 331 insertions(+), 50 deletions(-) create mode 100644 packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res create mode 100644 packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res create mode 100644 packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Modifiers.res diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res new file mode 100644 index 00000000..4f490bd5 --- /dev/null +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res @@ -0,0 +1,52 @@ +module Expression = Reducer_Expression +module ExpressionT = Reducer_Expression_T +module ErrorValue = Reducer_ErrorValue +module InternalExpressionValue = ReducerInterface_InternalExpressionValue +module Module = Reducer_Module +module T = Reducer_Type_T +module TypeChecker = Reducer_Type_TypeChecker + +open Jest +open Expect + +let checkArgumentsSourceCode = (aTypeSourceCode: string, sourceCode: string): result< + 'v, + ErrorValue.t, +> => { + let reducerFn = Expression.reduceExpression + let rResult = + Reducer.parse(sourceCode)->Belt.Result.flatMap(expr => + reducerFn(expr, Module.emptyBindings, InternalExpressionValue.defaultEnvironment) + ) + rResult->Belt.Result.flatMap(result => + switch result { + | IEvArray(args) => TypeChecker.checkArguments(aTypeSourceCode, args, reducerFn) + | _ => Js.Exn.raiseError("Arguments has to be an array") + } + ) +} + +let myCheckArguments = (aTypeSourceCode: string, sourceCode: string): string => + switch checkArgumentsSourceCode(aTypeSourceCode, sourceCode) { + | Ok(_) => "Ok" + | Error(error) => ErrorValue.errorToString(error) + } + +let myCheckArgumentsExpectEqual = (aTypeSourceCode, sourceCode, answer) => + expect(myCheckArguments(aTypeSourceCode, sourceCode))->toEqual(answer) + +let _myCheckArgumentsTest = (test, aTypeSourceCode, sourceCode, answer) => + test(aTypeSourceCode, () => myCheckArgumentsExpectEqual(aTypeSourceCode, sourceCode, answer)) + +let myCheckArgumentsTest = (aTypeSourceCode, sourceCode, answer) => + _myCheckArgumentsTest(test, aTypeSourceCode, sourceCode, answer) +module MySkip = { + let myCheckArgumentsTest = (aTypeSourceCode, sourceCode, answer) => + _myCheckArgumentsTest(Skip.test, aTypeSourceCode, sourceCode, answer) +} +module MyOnly = { + let myCheckArgumentsTest = (aTypeSourceCode, sourceCode, answer) => + _myCheckArgumentsTest(Only.test, aTypeSourceCode, sourceCode, answer) +} + +myCheckArgumentsTest("number=>number=>number", "[1,2]", "Ok") diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res new file mode 100644 index 00000000..5b093060 --- /dev/null +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res @@ -0,0 +1,78 @@ +module Expression = Reducer_Expression +module ExpressionT = Reducer_Expression_T +module ErrorValue = Reducer_ErrorValue +module InternalExpressionValue = ReducerInterface_InternalExpressionValue +module Module = Reducer_Module +module T = Reducer_Type_T +module TypeChecker = Reducer_Type_TypeChecker + +open Jest +open Expect + +// In development, you are expected to use TypeChecker.isTypeOf(aTypeSourceCode, result, reducerFn). +// isTypeOfSourceCode is written to use strings instead of expression values. + +let isTypeOfSourceCode = (aTypeSourceCode: string, sourceCode: string): result< + 'v, + ErrorValue.t, +> => { + let reducerFn = Expression.reduceExpression + let rResult = + Reducer.parse(sourceCode)->Belt.Result.flatMap(expr => + reducerFn(expr, Module.emptyBindings, InternalExpressionValue.defaultEnvironment) + ) + rResult->Belt.Result.flatMap(result => TypeChecker.isTypeOf(aTypeSourceCode, result, reducerFn)) +} + +let myTypeCheck = (aTypeSourceCode: string, sourceCode: string): string => + switch isTypeOfSourceCode(aTypeSourceCode, sourceCode) { + | Ok(_) => "Ok" + | Error(error) => ErrorValue.errorToString(error) + } + +let myTypeCheckExpectEqual = (aTypeSourceCode, sourceCode, answer) => + expect(myTypeCheck(aTypeSourceCode, sourceCode))->toEqual(answer) + +let _myTypeCheckTest = (test, aTypeSourceCode, sourceCode, answer) => + test(aTypeSourceCode, () => myTypeCheckExpectEqual(aTypeSourceCode, sourceCode, answer)) + +let myTypeCheckTest = (aTypeSourceCode, sourceCode, answer) => + _myTypeCheckTest(test, aTypeSourceCode, sourceCode, answer) +module MySkip = { + let myTypeCheckTest = (aTypeSourceCode, sourceCode, answer) => + _myTypeCheckTest(Skip.test, aTypeSourceCode, sourceCode, answer) +} +module MyOnly = { + let myTypeCheckTest = (aTypeSourceCode, sourceCode, answer) => + _myTypeCheckTest(Only.test, aTypeSourceCode, sourceCode, answer) +} + +myTypeCheckTest("number", "1", "Ok") +myTypeCheckTest("number", "'2'", "Expected type: number but got: '2'") +myTypeCheckTest("string", "3", "Expected type: string but got: 3") +myTypeCheckTest("string", "'a'", "Ok") +myTypeCheckTest("[number]", "[1,2,3]", "Ok") +myTypeCheckTest("[number]", "['a','a','a']", "Expected type: number but got: 'a'") +myTypeCheckTest("[number]", "[1,'a',3]", "Expected type: number but got: 'a'") +myTypeCheckTest("[number, string]", "[1,'a']", "Ok") +myTypeCheckTest("[number, string]", "[1, 2]", "Expected type: string but got: 2") +myTypeCheckTest( + "[number, string, string]", + "[1,'a']", + "Expected type: [number, string, string] but got: [1,'a']", +) +myTypeCheckTest( + "[number, string]", + "[1,'a', 3]", + "Expected type: [number, string] but got: [1,'a',3]", +) +myTypeCheckTest("{age: number, name: string}", "{age: 1, name: 'a'}", "Ok") +myTypeCheckTest( + "{age: number, name: string}", + "{age: 1, name: 'a', job: 'IT'}", + "Expected type: {age: number, name: string} but got: {age: 1,job: 'IT',name: 'a'}", +) +myTypeCheckTest("number | string", "1", "Ok") +myTypeCheckTest("date | string", "1", "Expected type: (date | string) but got: 1") +myTypeCheckTest("number<-min(10)", "10", "Ok") +myTypeCheckTest("number<-min(10)", "0", "Expected type: number<-min(10) but got: 0") diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros.res index e0e6902e..397265ae 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros.res @@ -144,7 +144,7 @@ let dispatchMacroCall = ( let ifTrueBlock = eBlock(list{ifTrue}) ExpressionWithContext.withContext(ifTrueBlock, bindings)->Ok } - | _ => REExpectedType("Boolean")->Error + | _ => REExpectedType("Boolean", "")->Error } ) } diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res index beaee7f7..211c9f53 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res @@ -7,7 +7,7 @@ type errorValue = | REArrayIndexNotFound(string, int) | REAssignmentExpected | REDistributionError(DistributionTypes.error) - | REExpectedType(string) + | REExpectedType(string, string) | REExpressionExpected | REFunctionExpected(string) | REFunctionNotFound(string) @@ -55,6 +55,6 @@ let errorToString = err => | RESymbolNotFound(symbolName) => `${symbolName} is not defined` | RESyntaxError(desc, _) => `Syntax Error: ${desc}` | RETodo(msg) => `TODO: ${msg}` - | REExpectedType(typeName) => `Expected type: ${typeName}` + | REExpectedType(typeName, valueString) => `Expected type: ${typeName} but got: ${valueString}` | REUnitNotFound(unitName) => `Unit not found: ${unitName}` } diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Modifiers.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Modifiers.res new file mode 100644 index 00000000..457e97d8 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Modifiers.res @@ -0,0 +1,53 @@ +module InternalExpressionValue = ReducerInterface_InternalExpressionValue +module T = Reducer_Type_T + +let isMin = (modifierArg: InternalExpressionValue.t, aValue: InternalExpressionValue.t): bool => { + let pair = (modifierArg, aValue) + switch pair { + | (IEvNumber(a), IEvNumber(b)) => a <= b + | _ => false + } +} + +let isMax = (modifierArg: InternalExpressionValue.t, aValue: InternalExpressionValue.t): bool => { + let pair = (modifierArg, aValue) + switch pair { + | (IEvNumber(a), IEvNumber(b)) => a >= b + | _ => false + } +} + +let isMemberOf = ( + modifierArg: InternalExpressionValue.t, + aValue: InternalExpressionValue.t, +): bool => { + let pair = (modifierArg, aValue) + switch pair { + | (ievA, IEvArray(b)) => Js.Array2.includes(b, ievA) + | _ => false + } +} + +let checkModifier = ( + key: string, + modifierArg: InternalExpressionValue.t, + aValue: InternalExpressionValue.t, +): bool => + switch key { + | "min" => isMin(modifierArg, aValue) + | "max" => isMax(modifierArg, aValue) + | "isMemberOf" => isMemberOf(modifierArg, aValue) + | _ => false + } + +let checkModifiers = ( + modifiers: Belt.Map.String.t, + aValue: InternalExpressionValue.t, +): bool => { + modifiers->Belt.Map.String.reduce(true, (acc, key, modifierArg) => + switch acc { + | true => checkModifier(key, modifierArg, aValue) + | _ => acc + } + ) +} diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res index 0e3b240d..d8011d23 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res @@ -11,6 +11,7 @@ type rec iType = | ItTypeRecord({properties: Belt.Map.String.t}) type t = iType +type typeErrorValue = TypeMismatch(t, InternalExpressionValue.t) let rec toString = (t: t): string => { switch t { diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res index a1a6bdc2..2778d3e4 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res @@ -1,71 +1,168 @@ -// module ErrorValue = Reducer_ErrorValue +module ExpressionT = Reducer_Expression_T module InternalExpressionValue = ReducerInterface_InternalExpressionValue module T = Reducer_Type_T -// module TypeBuilder = Reducer_Type_TypeBuilder +module TypeModifiers = Reducer_Type_Modifiers open InternalExpressionValue -type typeErrorValue = TypeError(T.t, InternalExpressionValue.t) - -let rec isOfResolvedIType = (anIType: T.iType, aValue): result => { +let rec isITypeOf = (anIType: T.iType, aValue): result => { let caseTypeIdentifier = (anUpperTypeName, aValue) => { let aTypeName = anUpperTypeName->Js.String2.toLowerCase let valueTypeName = aValue->valueToValueType->valueTypeToString->Js.String2.toLowerCase - switch aTypeName === valueTypeName { + switch aTypeName == valueTypeName { | true => Ok(true) - | false => TypeError(anIType, aValue)->Error + | false => T.TypeMismatch(anIType, aValue)->Error } } - let _caseRecord = (anIType, evValue, propertyMap, map) => { - Belt.Map.String.reduce(propertyMap, Ok(true), (acc, property, propertyType) => { + let caseRecord = (anIType, propertyMap: Belt.Map.String.t, evValue) => + switch evValue { + | IEvRecord(aRecord) => + if ( + Js.Array2.length(propertyMap->Belt.Map.String.keysToArray) == + Js.Array2.length(aRecord->Belt.Map.String.keysToArray) + ) { + Belt.Map.String.reduce(propertyMap, Ok(true), (acc, property, propertyType) => { + Belt.Result.flatMap(acc, _ => + switch Belt.Map.String.get(aRecord, property) { + | Some(propertyValue) => isITypeOf(propertyType, propertyValue) + | None => T.TypeMismatch(anIType, evValue)->Error + } + ) + }) + } else { + T.TypeMismatch(anIType, evValue)->Error + } + + | _ => T.TypeMismatch(anIType, evValue)->Error + } + + let caseArray = (anIType, elementType, evValue) => + switch evValue { + | IEvArray(anArray) => + Belt.Array.reduce(anArray, Ok(true), (acc, element) => + Belt.Result.flatMap(acc, _ => + switch isITypeOf(elementType, element) { + | Ok(_) => Ok(true) + | Error(error) => error->Error + } + ) + ) + | _ => T.TypeMismatch(anIType, evValue)->Error + } + + let caseTuple = (anIType, elementTypes, evValue) => + switch evValue { + | IEvArray(anArray) => + if Js.Array2.length(elementTypes) == Js.Array2.length(anArray) { + let zipped = Belt.Array.zip(elementTypes, anArray) + Belt.Array.reduce(zipped, Ok(true), (acc, (elementType, element)) => + switch acc { + | Ok(_) => + switch isITypeOf(elementType, element) { + | Ok(_) => acc + | Error(error) => Error(error) + } + | _ => acc + } + ) + } else { + T.TypeMismatch(anIType, evValue)->Error + } + | _ => T.TypeMismatch(anIType, evValue)->Error + } + + let caseOr = (anIType, anITypeArray, evValue) => + switch Belt.Array.reduce(anITypeArray, Ok(false), (acc, anIType) => Belt.Result.flatMap(acc, _ => - switch Belt.Map.String.get(map, property) { - | Some(propertyValue) => isOfResolvedIType(propertyType, propertyValue) - | None => TypeError(anIType, evValue)->Error + switch acc { + | Ok(false) => + switch isITypeOf(anIType, evValue) { + | Ok(_) => Ok(true) + | Error(_) => acc + } + | _ => acc } ) - }) - } - let _caseArray = (anIType, evValue, elementType, anArray) => { - Belt.Array.reduceWithIndex(anArray, Ok(true), (acc, element, _index) => { - switch isOfResolvedIType(elementType, element) { - | Ok(_) => acc - | Error(_) => TypeError(anIType, evValue)->Error + ) { + | Ok(true) => Ok(true) + | Ok(false) => T.TypeMismatch(anIType, evValue)->Error + | Error(error) => Error(error) + } + + let caseModifiedType = ( + anIType: T.iType, + modifiedType: T.iType, + modifiers: Belt.Map.String.t, + aValue: InternalExpressionValue.t, + ) => { + isITypeOf(modifiedType, aValue)->Belt.Result.flatMap(_result => { + if TypeModifiers.checkModifiers(modifiers, aValue) { + Ok(true) + } else { + T.TypeMismatch(anIType, aValue)->Error } }) } switch anIType { | ItTypeIdentifier(name) => caseTypeIdentifier(name, aValue) - // TODO: Work in progress. Code is commented to make an a release of other features - // | ItModifiedType({modifiedType: anIType}) => raise(Reducer_Exception.ImpossibleException) - // | ItTypeOr({typeOr: anITypeArray}) => raise(Reducer_Exception.ImpossibleException) - // | ItTypeFunction({inputs: anITypeArray, output: anIType}) => - // raise(Reducer_Exception.ImpossibleException) - // | ItTypeArray({element: anIType}) => raise(Reducer_Exception.ImpossibleException) - // | ItTypeTuple({elements: anITypeArray}) => raise(Reducer_Exception.ImpossibleException) - // | ItTypeRecord({properties: anITypeMap}) => raise(Reducer_Exception.ImpossibleException) - | _ => raise(Reducer_Exception.ImpossibleException("Reducer_TypeChecker-isOfResolvedIType")) + | ItModifiedType({modifiedType, modifiers}) => + caseModifiedType(anIType, modifiedType, modifiers, aValue) //{modifiedType: iType, modifiers: Belt.Map.String.t} + | ItTypeOr({typeOr}) => caseOr(anIType, typeOr, aValue) + | ItTypeFunction(_) => + raise( + Reducer_Exception.ImpossibleException( + "Reducer_TypeChecker-functions are without a type at the moment", + ), + ) + | ItTypeArray({element}) => caseArray(anIType, element, aValue) + | ItTypeTuple({elements}) => caseTuple(anIType, elements, aValue) + | ItTypeRecord({properties}) => caseRecord(anIType, properties, aValue) } } -// let isOfResolvedType = (aType: InternalExpressionValue.t, aValue): result => -// aType->T.fromIEvValue->isOfResolvedIType(aValue) +let isTypeOf = ( + typeExpressionSourceCode: string, + aValue: InternalExpressionValue.t, + reducerFn: ExpressionT.reducerFn, +): result => { + switch typeExpressionSourceCode->Reducer_Type_Compile.fromTypeExpression(reducerFn) { + | Ok(anIType) => + switch isITypeOf(anIType, aValue) { + | Ok(_) => Ok(aValue) + | Error(T.TypeMismatch(anIType, evValue)) => + Error( + ErrorValue.REExpectedType(anIType->T.toString, evValue->InternalExpressionValue.toString), + ) + } + | Error(error) => Error(error) // Directly propagating - err => err - causes type mismatch + } +} -// TODO: Work in progress. Code is commented to make an a release of other features -// let checkArguments = ( -// evFunctionType: InternalExpressionValue.t, -// args: array, -// ) => { -// let functionType = switch evFunctionType { -// | IEvRecord(functionType) => functionType -// | _ => raise(Reducer_Exception.ImpossibleException) -// } -// let evInputs = functionType->Belt.Map.String.getWithDefault("inputs", []->IEvArray) -// let inputs = switch evInputs { -// | IEvArray(inputs) => inputs -// | _ => raise(Reducer_Exception.ImpossibleException) -// } -// let rTupleType = TypeBuilder.typeTuple(inputs) -// Belt.Result.flatMap(rTupleType, tupleType => isOfResolvedType(tupleType, args->IEvArray)) -// } +let checkITypeArguments = (anIType: T.iType, args: array): result< + bool, + T.typeErrorValue, +> => { + switch anIType { + | T.ItTypeFunction({inputs}) => isITypeOf(T.ItTypeTuple({elements: inputs}), args->IEvArray) + | _ => T.TypeMismatch(anIType, args->IEvArray)->Error + } +} + +let checkArguments = ( + typeExpressionSourceCode: string, + args: array, + reducerFn: ExpressionT.reducerFn, +): result => { + switch typeExpressionSourceCode->Reducer_Type_Compile.fromTypeExpression(reducerFn) { + | Ok(anIType) => + switch checkITypeArguments(anIType, args) { + | Ok(_) => Ok(args->IEvArray) + | Error(T.TypeMismatch(anIType, evValue)) => + Error( + ErrorValue.REExpectedType(anIType->T.toString, evValue->InternalExpressionValue.toString), + ) + } + | Error(error) => Error(error) // Directly propagating - err => err - causes type mismatch + } +} From 6966c8d3e51ef8fac1b9870ede6aec561baaf7dc Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 18 Jul 2022 15:17:41 +0200 Subject: [PATCH 04/19] ternary validation --- .../__tests__/Reducer/Reducer_ternaryOperator_test.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_ternaryOperator_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_ternaryOperator_test.res index 25353e89..22fa8328 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_ternaryOperator_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_ternaryOperator_test.res @@ -10,5 +10,5 @@ describe("Evaluate ternary operator", () => { testEvalToBe("false ? 'YES' : 'NO'", "Ok('NO')") testEvalToBe("2 > 1 ? 'YES' : 'NO'", "Ok('YES')") testEvalToBe("2 <= 1 ? 'YES' : 'NO'", "Ok('NO')") - testEvalToBe("1+1 ? 'YES' : 'NO'", "Error(Expected type: Boolean)") + testEvalToBe("1+1 ? 'YES' : 'NO'", "Error(Expected type: Boolean but got: )") }) From 8f742bf99f011f1cac69d8a38652b5c224b1cdde Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Mon, 18 Jul 2022 08:47:02 -0700 Subject: [PATCH 05/19] Quick fix for component --- packages/components/src/components/FunctionChart1Dist.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/components/src/components/FunctionChart1Dist.tsx b/packages/components/src/components/FunctionChart1Dist.tsx index 650d2753..f8d072d7 100644 --- a/packages/components/src/components/FunctionChart1Dist.tsx +++ b/packages/components/src/components/FunctionChart1Dist.tsx @@ -88,7 +88,7 @@ let getPercentiles = ({ chartSettings, fn, environment }) => { let chartPointsData: point[] = chartPointsToRender.map((x) => { let result = runForeign(fn, [x], environment); if (result.tag === "Ok") { - if (result.value.tag == "distribution") { + if (result.value.tag === "distribution") { return { x, value: { tag: "Ok", value: result.value.value } }; } else { return { @@ -165,12 +165,14 @@ export const FunctionChart1Dist: React.FC = ({ setMouseOverlay(NaN); } const signalListeners = { mousemove: handleHover, mouseout: handleOut }; + + //TODO: This custom error handling is a bit hacky and should be improved. let mouseItem: result = !!mouseOverlay ? runForeign(fn, [mouseOverlay], environment) : { tag: "Error", value: { - tag: "REExpectedType", + tag: "RETodo", value: "Hover x-coordinate returned NaN. Expected a number.", }, }; From c1429e09078a8669b34ce55b61f94490d2fc1a29 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 18 Jul 2022 18:16:49 +0200 Subject: [PATCH 06/19] simplified modules --- .../Reducer_Peggy_ToExpression_test.res | 1 - .../Reducer_Type/Reducer_Type_Compile_test.res | 2 +- .../Reducer_Type_TypeChecker_arguments_test.res | 4 ++-- .../Reducer_Type/Reducer_Type_TypeChecker_test.res | 4 ++-- .../Reducer/Reducer_Bindings/Reducer_Bindings.res | 3 +++ .../Reducer/Reducer_Type/Reducer_Type_Compile.res | 12 ++++++++---- .../ReducerInterface_InternalExpressionValue.res | 2 +- 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res index 74bf59e0..b8a81f25 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res @@ -3,7 +3,6 @@ module InternalExpressionValue = ReducerInterface_InternalExpressionValue open Jest open Reducer_Peggy_TestHelpers -open Expect describe("Peggy to Expression", () => { describe("literals operators parenthesis", () => { diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res index 3f97ca3f..4de688d1 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res @@ -1,6 +1,6 @@ module Expression = Reducer_Expression module InternalExpressionValue = ReducerInterface_InternalExpressionValue -module Module = Reducer_Module +module Bindings = Reducer_Bindings module T = Reducer_Type_T module TypeCompile = Reducer_Type_Compile diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res index 4f490bd5..9c23e38e 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res @@ -2,7 +2,7 @@ module Expression = Reducer_Expression module ExpressionT = Reducer_Expression_T module ErrorValue = Reducer_ErrorValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue -module Module = Reducer_Module +module Bindings = Reducer_Bindings module T = Reducer_Type_T module TypeChecker = Reducer_Type_TypeChecker @@ -16,7 +16,7 @@ let checkArgumentsSourceCode = (aTypeSourceCode: string, sourceCode: string): re let reducerFn = Expression.reduceExpression let rResult = Reducer.parse(sourceCode)->Belt.Result.flatMap(expr => - reducerFn(expr, Module.emptyBindings, InternalExpressionValue.defaultEnvironment) + reducerFn(expr, Bindings.emptyBindings, InternalExpressionValue.defaultEnvironment) ) rResult->Belt.Result.flatMap(result => switch result { diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res index 5b093060..d845d550 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res @@ -2,7 +2,7 @@ module Expression = Reducer_Expression module ExpressionT = Reducer_Expression_T module ErrorValue = Reducer_ErrorValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue -module Module = Reducer_Module +module Bindings = Reducer_Bindings module T = Reducer_Type_T module TypeChecker = Reducer_Type_TypeChecker @@ -19,7 +19,7 @@ let isTypeOfSourceCode = (aTypeSourceCode: string, sourceCode: string): result< let reducerFn = Expression.reduceExpression let rResult = Reducer.parse(sourceCode)->Belt.Result.flatMap(expr => - reducerFn(expr, Module.emptyBindings, InternalExpressionValue.defaultEnvironment) + reducerFn(expr, Bindings.emptyBindings, InternalExpressionValue.defaultEnvironment) ) rResult->Belt.Result.flatMap(result => TypeChecker.isTypeOf(aTypeSourceCode, result, reducerFn)) } diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res index f02cd54f..28175d7a 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res @@ -1,3 +1,6 @@ +// Only Bindings as the global module is supported +// Other module operations such as import export will be prepreocessed jobs + module ExpressionT = Reducer_Expression_T module InternalExpressionValue = ReducerInterface_InternalExpressionValue open Reducer_ErrorValue diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res index c7a776b7..2119ee62 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res @@ -1,7 +1,7 @@ module ErrorValue = Reducer_ErrorValue module ExpressionT = Reducer_Expression_T module InternalExpressionValue = ReducerInterface_InternalExpressionValue -module Module = Reducer_Module +module Bindings = Reducer_Bindings module T = Reducer_Type_T let ievFromTypeExpression = ( @@ -11,11 +11,15 @@ let ievFromTypeExpression = ( let sIndex = "compiled" let sourceCode = `type ${sIndex}=${typeExpressionSourceCode}` Reducer_Expression.parse(sourceCode)->Belt.Result.flatMap(expr => { - let rContext = reducerFn(expr, Module.emptyBindings, InternalExpressionValue.defaultEnvironment) + let rContext = reducerFn( + expr, + Bindings.emptyBindings, + InternalExpressionValue.defaultEnvironment, + ) Belt.Result.map(rContext, context => switch context { - | IEvModule(nameSpace) => - switch Module.getType(nameSpace, sIndex) { + | IEvBindings(nameSpace) => + switch Bindings.getType(nameSpace, sIndex) { | Some(value) => value | None => raise(Reducer_Exception.ImpossibleException("Reducer_Type_Compile-none")) } diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res index 06ab2376..4523b02a 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res @@ -84,7 +84,7 @@ let toStringWithType = aValue => | IEvDeclaration(_) => `Declaration::${toString(aValue)}` | IEvDistribution(_) => `Distribution::${toString(aValue)}` | IEvLambda(_) => `Lambda::${toString(aValue)}` - | IEvBindings(_) => `Module::${toString(aValue)}` + | IEvBindings(_) => `Bindings::${toString(aValue)}` | IEvNumber(_) => `Number::${toString(aValue)}` | IEvRecord(_) => `Record::${toString(aValue)}` | IEvString(_) => `String::${toString(aValue)}` From bcd74eefda9ee8d324964636a8ffec63543a3953 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:19:30 +0000 Subject: [PATCH 07/19] :arrow_up: Bump commander from 9.3.0 to 9.4.0 Bumps [commander](https://github.com/tj/commander.js) from 9.3.0 to 9.4.0. - [Release notes](https://github.com/tj/commander.js/releases) - [Changelog](https://github.com/tj/commander.js/blob/master/CHANGELOG.md) - [Commits](https://github.com/tj/commander.js/compare/v9.3.0...v9.4.0) --- updated-dependencies: - dependency-name: commander dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- packages/cli/package.json | 2 +- yarn.lock | 52 ++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 053d8096..2890d2a4 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -13,7 +13,7 @@ "dependencies": { "chalk": "^5.0.1", "chokidar": "^3.5.3", - "commander": "^9.3.0", + "commander": "^9.4.0", "fs": "^0.0.1-security", "glob": "^8.0.3", "indent-string": "^5.0.0" diff --git a/yarn.lock b/yarn.lock index 62b18492..0edee2dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2382,10 +2382,10 @@ resolved "https://registry.yarnpkg.com/@heroicons/react/-/react-1.0.6.tgz#35dd26987228b39ef2316db3b1245c42eb19e324" integrity sha512-JJCXydOFWMDpCP4q13iEplA503MQO3xLoZiKum+955ZCtHINWnx26CUxVxxFQu/uLb4LW3ge15ZpzIkXKkJ8oQ== -"@hookform/resolvers@^2.9.5": - version "2.9.5" - resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-2.9.5.tgz#adfa2d240a9315f4ab6ff4c63621d22d1b574c07" - integrity sha512-4XABrKdE4GpX6v2RZ+Ij1Wrl9qPEl5ZvVhFxROY+SZhP/6TU8gPw0LO4ZS9/GgIbTx3Pw1U8HmcXVAoGOq+7iA== +"@hookform/resolvers@^2.9.6": + version "2.9.6" + resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-2.9.6.tgz#db4277a96d1817d94169108167014926d8a10398" + integrity sha512-f4VxF8w9rdX0WsDCk3FW1dGPj/Sj8+1Ulcgtm5ymgWEpbA/fjY+NUDh+L9hftmxDgP8+EJFtF+qFK4gPEXVrVQ== "@humanwhocodes/config-array@^0.9.2": version "0.9.5" @@ -4535,10 +4535,10 @@ "@testing-library/dom" "^8.5.0" "@types/react-dom" "^18.0.0" -"@testing-library/user-event@^14.2.1": - version "14.2.1" - resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.2.1.tgz#8c5ff2d004544bb2220e1d864f7267fe7eb6c556" - integrity sha512-HOr1QiODrq+0j9lKU5i10y9TbhxMBMRMGimNx10asdmau9cb8Xb1Vyg0GvTwyIL2ziQyh2kAloOtAQFBQVuecA== +"@testing-library/user-event@^14.2.6": + version "14.2.6" + resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.2.6.tgz#9ba313a212994eea66e018520e23542ac3eb6fbe" + integrity sha512-l/4W4x3Lm24wkWNkPasXqvEzG+a6n2X872XCUjhyfbNqcoOapaWyCxC5Fz+E4r7JPu8gysQKSSCrK0OO2x+D+A== "@tootallnate/once@1": version "1.1.2" @@ -7370,10 +7370,10 @@ commander@^8.0.0, commander@^8.3.0: resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66" integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww== -commander@^9.3.0: - version "9.3.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-9.3.0.tgz#f619114a5a2d2054e0d9ff1b31d5ccf89255e26b" - integrity sha512-hv95iU5uXPbK83mjrJKuZyFM/LBAoCV/XhVGkS5Je6tl7sxr6A0ITMw5WoRV46/UaJ46Nllm3Xt7IaJhXTIkzw== +commander@^9.3.0, commander@^9.4.0: + version "9.4.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-9.4.0.tgz#bc4a40918fefe52e22450c111ecd6b7acce6f11c" + integrity sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw== common-path-prefix@^3.0.0: version "3.0.0" @@ -9091,10 +9091,10 @@ eslint-webpack-plugin@^3.1.1: normalize-path "^3.0.0" schema-utils "^3.1.1" -eslint@^8.19.0, eslint@^8.3.0: - version "8.19.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.19.0.tgz#7342a3cbc4fbc5c106a1eefe0fd0b50b6b1a7d28" - integrity sha512-SXOPj3x9VKvPe81TjjUJCYlV4oJjQw68Uek+AM0X4p+33dj2HY5bpTZOgnQHcG2eAm1mtCU9uNMnJi7exU/kYw== +eslint@^8.20.0, eslint@^8.3.0: + version "8.20.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.20.0.tgz#048ac56aa18529967da8354a478be4ec0a2bc81b" + integrity sha512-d4ixhz5SKCa1D6SCPrivP7yYVi7nyD6A4vs6HIAul9ujBzcEmZVM3/0NN/yu5nKhmO1wjp5xQ46iRfmDGlOviA== dependencies: "@eslint/eslintrc" "^1.3.0" "@humanwhocodes/config-array" "^0.9.2" @@ -14224,7 +14224,15 @@ postcss-lab-function@^4.2.0: "@csstools/postcss-progressive-custom-properties" "^1.1.0" postcss-value-parser "^4.2.0" -postcss-load-config@^4.0.0, postcss-load-config@^4.0.1: +postcss-load-config@^3.1.4: + version "3.1.4" + resolved "https://registry.yarnpkg.com/postcss-load-config/-/postcss-load-config-3.1.4.tgz#1ab2571faf84bb078877e1d07905eabe9ebda855" + integrity sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg== + dependencies: + lilconfig "^2.0.5" + yaml "^1.10.2" + +postcss-load-config@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/postcss-load-config/-/postcss-load-config-4.0.1.tgz#152383f481c2758274404e4962743191d73875bd" integrity sha512-vEJIc8RdiBRu3oRAI0ymerOn+7rPuMvRXslTvZUKZonDHFIczxztIyJ1urxM1x9JXEikvpWWTUUqal5j/8QgvA== @@ -17124,10 +17132,10 @@ synchronous-promise@^2.0.15: resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-2.0.15.tgz#07ca1822b9de0001f5ff73595f3d08c4f720eb8e" integrity sha512-k8uzYIkIVwmT+TcglpdN50pS2y1BDcUnBPK9iJeGu0Pl1lOI8pD6wtzgw91Pjpe+RxtTncw32tLxs/R0yNL2Mg== -tailwindcss@^3.0.2, tailwindcss@^3.1.5: - version "3.1.5" - resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.1.5.tgz#c8e0bb1cbacf29a6411d9c07debc1af9d388d4ca" - integrity sha512-bC/2dy3dGPqxMWAqFSRgQxVCfmO/31ZbeEp8s9DMDh4zgPZ5WW1gxRJkbBkXcTUIzaSUdhWrcsrSOe32ccgB4w== +tailwindcss@^3.0.2, tailwindcss@^3.1.6: + version "3.1.6" + resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.1.6.tgz#bcb719357776c39e6376a8d84e9834b2b19a49f1" + integrity sha512-7skAOY56erZAFQssT1xkpk+kWt2NrO45kORlxFPXUt3CiGsVPhH1smuH5XoDH6sGPXLyBv+zgCKA2HWBsgCytg== dependencies: arg "^5.0.2" chokidar "^3.5.3" @@ -17145,7 +17153,7 @@ tailwindcss@^3.0.2, tailwindcss@^3.1.5: postcss "^8.4.14" postcss-import "^14.1.0" postcss-js "^4.0.0" - postcss-load-config "^4.0.1" + postcss-load-config "^3.1.4" postcss-nested "5.0.6" postcss-selector-parser "^6.0.10" postcss-value-parser "^4.2.0" From fe4e475ff48199584629462b9116ae7d7c5d605d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:24:23 +0000 Subject: [PATCH 08/19] :arrow_up: Bump @types/node from 18.0.3 to 18.0.6 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.0.3 to 18.0.6. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- packages/components/package.json | 8 ++--- yarn.lock | 52 ++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/packages/components/package.json b/packages/components/package.json index 765a0c0a..d8900346 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -5,7 +5,7 @@ "dependencies": { "@headlessui/react": "^1.6.6", "@heroicons/react": "^1.0.6", - "@hookform/resolvers": "^2.9.5", + "@hookform/resolvers": "^2.9.6", "@quri/squiggle-lang": "^0.2.8", "@react-hook/size": "^2.1.2", "clsx": "^1.2.1", @@ -34,10 +34,10 @@ "@storybook/react": "^6.5.9", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", - "@testing-library/user-event": "^14.2.1", + "@testing-library/user-event": "^14.2.6", "@types/jest": "^27.5.0", "@types/lodash": "^4.14.182", - "@types/node": "^18.0.3", + "@types/node": "^18.0.6", "@types/react": "^18.0.9", "@types/styled-components": "^5.1.24", "@types/webpack": "^5.28.0", @@ -49,7 +49,7 @@ "react": "^18.1.0", "react-scripts": "^5.0.1", "style-loader": "^3.3.1", - "tailwindcss": "^3.1.5", + "tailwindcss": "^3.1.6", "ts-loader": "^9.3.0", "tsconfig-paths-webpack-plugin": "^3.5.2", "typescript": "^4.7.4", diff --git a/yarn.lock b/yarn.lock index 62b18492..f5354481 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2382,10 +2382,10 @@ resolved "https://registry.yarnpkg.com/@heroicons/react/-/react-1.0.6.tgz#35dd26987228b39ef2316db3b1245c42eb19e324" integrity sha512-JJCXydOFWMDpCP4q13iEplA503MQO3xLoZiKum+955ZCtHINWnx26CUxVxxFQu/uLb4LW3ge15ZpzIkXKkJ8oQ== -"@hookform/resolvers@^2.9.5": - version "2.9.5" - resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-2.9.5.tgz#adfa2d240a9315f4ab6ff4c63621d22d1b574c07" - integrity sha512-4XABrKdE4GpX6v2RZ+Ij1Wrl9qPEl5ZvVhFxROY+SZhP/6TU8gPw0LO4ZS9/GgIbTx3Pw1U8HmcXVAoGOq+7iA== +"@hookform/resolvers@^2.9.6": + version "2.9.6" + resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-2.9.6.tgz#db4277a96d1817d94169108167014926d8a10398" + integrity sha512-f4VxF8w9rdX0WsDCk3FW1dGPj/Sj8+1Ulcgtm5ymgWEpbA/fjY+NUDh+L9hftmxDgP8+EJFtF+qFK4gPEXVrVQ== "@humanwhocodes/config-array@^0.9.2": version "0.9.5" @@ -4535,10 +4535,10 @@ "@testing-library/dom" "^8.5.0" "@types/react-dom" "^18.0.0" -"@testing-library/user-event@^14.2.1": - version "14.2.1" - resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.2.1.tgz#8c5ff2d004544bb2220e1d864f7267fe7eb6c556" - integrity sha512-HOr1QiODrq+0j9lKU5i10y9TbhxMBMRMGimNx10asdmau9cb8Xb1Vyg0GvTwyIL2ziQyh2kAloOtAQFBQVuecA== +"@testing-library/user-event@^14.2.6": + version "14.2.6" + resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.2.6.tgz#9ba313a212994eea66e018520e23542ac3eb6fbe" + integrity sha512-l/4W4x3Lm24wkWNkPasXqvEzG+a6n2X872XCUjhyfbNqcoOapaWyCxC5Fz+E4r7JPu8gysQKSSCrK0OO2x+D+A== "@tootallnate/once@1": version "1.1.2" @@ -4843,10 +4843,10 @@ "@types/node" "*" form-data "^3.0.0" -"@types/node@*", "@types/node@18.x", "@types/node@^18.0.3": - version "18.0.3" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.3.tgz#463fc47f13ec0688a33aec75d078a0541a447199" - integrity sha512-HzNRZtp4eepNitP+BD6k2L6DROIDG4Q0fm4x+dwfsr6LGmROENnok75VGw40628xf+iR24WeMFcHuuBDUAzzsQ== +"@types/node@*", "@types/node@18.x", "@types/node@^18.0.6": + version "18.0.6" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.6.tgz#0ba49ac517ad69abe7a1508bc9b3a5483df9d5d7" + integrity sha512-/xUq6H2aQm261exT6iZTMifUySEt4GR5KX8eYyY+C4MSNPqSh9oNIP7tz2GLKTlFaiBbgZNxffoR3CVRG+cljw== "@types/node@^14.0.10 || ^16.0.0", "@types/node@^14.14.20 || ^16.0.0": version "16.11.41" @@ -9091,10 +9091,10 @@ eslint-webpack-plugin@^3.1.1: normalize-path "^3.0.0" schema-utils "^3.1.1" -eslint@^8.19.0, eslint@^8.3.0: - version "8.19.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.19.0.tgz#7342a3cbc4fbc5c106a1eefe0fd0b50b6b1a7d28" - integrity sha512-SXOPj3x9VKvPe81TjjUJCYlV4oJjQw68Uek+AM0X4p+33dj2HY5bpTZOgnQHcG2eAm1mtCU9uNMnJi7exU/kYw== +eslint@^8.20.0, eslint@^8.3.0: + version "8.20.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.20.0.tgz#048ac56aa18529967da8354a478be4ec0a2bc81b" + integrity sha512-d4ixhz5SKCa1D6SCPrivP7yYVi7nyD6A4vs6HIAul9ujBzcEmZVM3/0NN/yu5nKhmO1wjp5xQ46iRfmDGlOviA== dependencies: "@eslint/eslintrc" "^1.3.0" "@humanwhocodes/config-array" "^0.9.2" @@ -14224,7 +14224,15 @@ postcss-lab-function@^4.2.0: "@csstools/postcss-progressive-custom-properties" "^1.1.0" postcss-value-parser "^4.2.0" -postcss-load-config@^4.0.0, postcss-load-config@^4.0.1: +postcss-load-config@^3.1.4: + version "3.1.4" + resolved "https://registry.yarnpkg.com/postcss-load-config/-/postcss-load-config-3.1.4.tgz#1ab2571faf84bb078877e1d07905eabe9ebda855" + integrity sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg== + dependencies: + lilconfig "^2.0.5" + yaml "^1.10.2" + +postcss-load-config@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/postcss-load-config/-/postcss-load-config-4.0.1.tgz#152383f481c2758274404e4962743191d73875bd" integrity sha512-vEJIc8RdiBRu3oRAI0ymerOn+7rPuMvRXslTvZUKZonDHFIczxztIyJ1urxM1x9JXEikvpWWTUUqal5j/8QgvA== @@ -17124,10 +17132,10 @@ synchronous-promise@^2.0.15: resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-2.0.15.tgz#07ca1822b9de0001f5ff73595f3d08c4f720eb8e" integrity sha512-k8uzYIkIVwmT+TcglpdN50pS2y1BDcUnBPK9iJeGu0Pl1lOI8pD6wtzgw91Pjpe+RxtTncw32tLxs/R0yNL2Mg== -tailwindcss@^3.0.2, tailwindcss@^3.1.5: - version "3.1.5" - resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.1.5.tgz#c8e0bb1cbacf29a6411d9c07debc1af9d388d4ca" - integrity sha512-bC/2dy3dGPqxMWAqFSRgQxVCfmO/31ZbeEp8s9DMDh4zgPZ5WW1gxRJkbBkXcTUIzaSUdhWrcsrSOe32ccgB4w== +tailwindcss@^3.0.2, tailwindcss@^3.1.6: + version "3.1.6" + resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.1.6.tgz#bcb719357776c39e6376a8d84e9834b2b19a49f1" + integrity sha512-7skAOY56erZAFQssT1xkpk+kWt2NrO45kORlxFPXUt3CiGsVPhH1smuH5XoDH6sGPXLyBv+zgCKA2HWBsgCytg== dependencies: arg "^5.0.2" chokidar "^3.5.3" @@ -17145,7 +17153,7 @@ tailwindcss@^3.0.2, tailwindcss@^3.1.5: postcss "^8.4.14" postcss-import "^14.1.0" postcss-js "^4.0.0" - postcss-load-config "^4.0.1" + postcss-load-config "^3.1.4" postcss-nested "5.0.6" postcss-selector-parser "^6.0.10" postcss-value-parser "^4.2.0" From 813c97db186fea80b20341a29de2673052d385b4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:25:40 +0000 Subject: [PATCH 09/19] :arrow_up: Bump vscode-languageclient from 8.0.1 to 8.0.2 Bumps [vscode-languageclient](https://github.com/Microsoft/vscode-languageserver-node/tree/HEAD/client) from 8.0.1 to 8.0.2. - [Release notes](https://github.com/Microsoft/vscode-languageserver-node/releases) - [Commits](https://github.com/Microsoft/vscode-languageserver-node/commits/release/client/8.0.2/client) --- updated-dependencies: - dependency-name: vscode-languageclient dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- packages/vscode-ext/package.json | 2 +- yarn.lock | 28 +++++----------------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/packages/vscode-ext/package.json b/packages/vscode-ext/package.json index 64747197..bd9ca529 100644 --- a/packages/vscode-ext/package.json +++ b/packages/vscode-ext/package.json @@ -148,7 +148,7 @@ "vsce-yarn-patch": "^1.66.2" }, "dependencies": { - "vscode-languageclient": "^8.0.1", + "vscode-languageclient": "^8.0.2", "vscode-languageserver": "^8.0.2", "vscode-languageserver-textdocument": "^1.0.5", "@quri/squiggle-lang": "^0.2.11" diff --git a/yarn.lock b/yarn.lock index 3893838f..41e5087e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18390,32 +18390,19 @@ vsce-yarn-patch@^1.66.2: yauzl "^2.3.1" yazl "^2.2.2" -vscode-jsonrpc@8.0.1: - version "8.0.1" - resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-8.0.1.tgz#f30b0625ebafa0fb3bc53e934ca47b706445e57e" - integrity sha512-N/WKvghIajmEvXpatSzvTvOIz61ZSmOSa4BRA4pTLi+1+jozquQKP/MkaylP9iB68k73Oua1feLQvH3xQuigiQ== - vscode-jsonrpc@8.0.2: version "8.0.2" resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-8.0.2.tgz#f239ed2cd6004021b6550af9fd9d3e47eee3cac9" integrity sha512-RY7HwI/ydoC1Wwg4gJ3y6LpU9FJRZAUnTYMXthqhFXXu77ErDd/xkREpGuk4MyYkk4a+XDWAMqe0S3KkelYQEQ== -vscode-languageclient@^8.0.1: - version "8.0.1" - resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-8.0.1.tgz#bf5535c4463a78daeaca0bcb4f5868aec86bb301" - integrity sha512-9XoE+HJfaWvu7Y75H3VmLo5WLCtsbxEgEhrLPqwt7eyoR49lUIyyrjb98Yfa50JCMqF2cePJAEVI6oe2o1sIhw== +vscode-languageclient@^8.0.2: + version "8.0.2" + resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-8.0.2.tgz#f1f23ce8c8484aa11e4b7dfb24437d3e59bb61c6" + integrity sha512-lHlthJtphG9gibGb/y72CKqQUxwPsMXijJVpHEC2bvbFqxmkj9LwQ3aGU9dwjBLqsX1S4KjShYppLvg1UJDF/Q== dependencies: minimatch "^3.0.4" semver "^7.3.5" - vscode-languageserver-protocol "3.17.1" - -vscode-languageserver-protocol@3.17.1: - version "3.17.1" - resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.1.tgz#e801762c304f740208b6c804a0cf21f2c87509ed" - integrity sha512-BNlAYgQoYwlSgDLJhSG+DeA8G1JyECqRzM2YO6tMmMji3Ad9Mw6AW7vnZMti90qlAKb0LqAlJfSVGEdqMMNzKg== - dependencies: - vscode-jsonrpc "8.0.1" - vscode-languageserver-types "3.17.1" + vscode-languageserver-protocol "3.17.2" vscode-languageserver-protocol@3.17.2: version "3.17.2" @@ -18430,11 +18417,6 @@ vscode-languageserver-textdocument@^1.0.5: resolved "https://registry.yarnpkg.com/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.5.tgz#838769940ece626176ec5d5a2aa2d0aa69f5095c" integrity sha512-1ah7zyQjKBudnMiHbZmxz5bYNM9KKZYz+5VQLj+yr8l+9w3g+WAhCkUkWbhMEdC5u0ub4Ndiye/fDyS8ghIKQg== -vscode-languageserver-types@3.17.1: - version "3.17.1" - resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.1.tgz#c2d87fa7784f8cac389deb3ff1e2d9a7bef07e16" - integrity sha512-K3HqVRPElLZVVPtMeKlsyL9aK0GxGQpvtAUTfX4k7+iJ4mc1M+JM+zQwkgGy2LzY0f0IAafe8MKqIkJrxfGGjQ== - vscode-languageserver-types@3.17.2: version "3.17.2" resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.2.tgz#b2c2e7de405ad3d73a883e91989b850170ffc4f2" From 03486a04538b1fc59c2398701f25bdd99495c320 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:27:45 +0000 Subject: [PATCH 10/19] :arrow_up: Bump framer-motion from 6.4.3 to 6.5.1 Bumps [framer-motion](https://github.com/framer/motion) from 6.4.3 to 6.5.1. - [Release notes](https://github.com/framer/motion/releases) - [Changelog](https://github.com/framer/motion/blob/main/CHANGELOG.md) - [Commits](https://github.com/framer/motion/compare/v6.4.3...v6.5.1) --- updated-dependencies: - dependency-name: framer-motion dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- packages/components/package.json | 8 ++--- yarn.lock | 56 ++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/packages/components/package.json b/packages/components/package.json index 765a0c0a..03b1eff1 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -5,11 +5,11 @@ "dependencies": { "@headlessui/react": "^1.6.6", "@heroicons/react": "^1.0.6", - "@hookform/resolvers": "^2.9.5", + "@hookform/resolvers": "^2.9.6", "@quri/squiggle-lang": "^0.2.8", "@react-hook/size": "^2.1.2", "clsx": "^1.2.1", - "framer-motion": "^6.4.3", + "framer-motion": "^6.5.1", "lodash": "^4.17.21", "react": "^18.1.0", "react-ace": "^10.1.0", @@ -34,7 +34,7 @@ "@storybook/react": "^6.5.9", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", - "@testing-library/user-event": "^14.2.1", + "@testing-library/user-event": "^14.2.6", "@types/jest": "^27.5.0", "@types/lodash": "^4.14.182", "@types/node": "^18.0.3", @@ -49,7 +49,7 @@ "react": "^18.1.0", "react-scripts": "^5.0.1", "style-loader": "^3.3.1", - "tailwindcss": "^3.1.5", + "tailwindcss": "^3.1.6", "ts-loader": "^9.3.0", "tsconfig-paths-webpack-plugin": "^3.5.2", "typescript": "^4.7.4", diff --git a/yarn.lock b/yarn.lock index 62b18492..f2fd7f5d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2382,10 +2382,10 @@ resolved "https://registry.yarnpkg.com/@heroicons/react/-/react-1.0.6.tgz#35dd26987228b39ef2316db3b1245c42eb19e324" integrity sha512-JJCXydOFWMDpCP4q13iEplA503MQO3xLoZiKum+955ZCtHINWnx26CUxVxxFQu/uLb4LW3ge15ZpzIkXKkJ8oQ== -"@hookform/resolvers@^2.9.5": - version "2.9.5" - resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-2.9.5.tgz#adfa2d240a9315f4ab6ff4c63621d22d1b574c07" - integrity sha512-4XABrKdE4GpX6v2RZ+Ij1Wrl9qPEl5ZvVhFxROY+SZhP/6TU8gPw0LO4ZS9/GgIbTx3Pw1U8HmcXVAoGOq+7iA== +"@hookform/resolvers@^2.9.6": + version "2.9.6" + resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-2.9.6.tgz#db4277a96d1817d94169108167014926d8a10398" + integrity sha512-f4VxF8w9rdX0WsDCk3FW1dGPj/Sj8+1Ulcgtm5ymgWEpbA/fjY+NUDh+L9hftmxDgP8+EJFtF+qFK4gPEXVrVQ== "@humanwhocodes/config-array@^0.9.2": version "0.9.5" @@ -2791,7 +2791,7 @@ "@motionone/utils" "^10.12.0" tslib "^2.3.1" -"@motionone/dom@^10.11.1": +"@motionone/dom@10.12.0": version "10.12.0" resolved "https://registry.yarnpkg.com/@motionone/dom/-/dom-10.12.0.tgz#ae30827fd53219efca4e1150a5ff2165c28351ed" integrity sha512-UdPTtLMAktHiqV0atOczNYyDd/d8Cf5fFsd1tua03PqTwwCe/6lwhLSQ8a7TbnQ5SN0gm44N1slBfj+ORIhrqw== @@ -4535,10 +4535,10 @@ "@testing-library/dom" "^8.5.0" "@types/react-dom" "^18.0.0" -"@testing-library/user-event@^14.2.1": - version "14.2.1" - resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.2.1.tgz#8c5ff2d004544bb2220e1d864f7267fe7eb6c556" - integrity sha512-HOr1QiODrq+0j9lKU5i10y9TbhxMBMRMGimNx10asdmau9cb8Xb1Vyg0GvTwyIL2ziQyh2kAloOtAQFBQVuecA== +"@testing-library/user-event@^14.2.6": + version "14.2.6" + resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.2.6.tgz#9ba313a212994eea66e018520e23542ac3eb6fbe" + integrity sha512-l/4W4x3Lm24wkWNkPasXqvEzG+a6n2X872XCUjhyfbNqcoOapaWyCxC5Fz+E4r7JPu8gysQKSSCrK0OO2x+D+A== "@tootallnate/once@1": version "1.1.2" @@ -9091,10 +9091,10 @@ eslint-webpack-plugin@^3.1.1: normalize-path "^3.0.0" schema-utils "^3.1.1" -eslint@^8.19.0, eslint@^8.3.0: - version "8.19.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.19.0.tgz#7342a3cbc4fbc5c106a1eefe0fd0b50b6b1a7d28" - integrity sha512-SXOPj3x9VKvPe81TjjUJCYlV4oJjQw68Uek+AM0X4p+33dj2HY5bpTZOgnQHcG2eAm1mtCU9uNMnJi7exU/kYw== +eslint@^8.20.0, eslint@^8.3.0: + version "8.20.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.20.0.tgz#048ac56aa18529967da8354a478be4ec0a2bc81b" + integrity sha512-d4ixhz5SKCa1D6SCPrivP7yYVi7nyD6A4vs6HIAul9ujBzcEmZVM3/0NN/yu5nKhmO1wjp5xQ46iRfmDGlOviA== dependencies: "@eslint/eslintrc" "^1.3.0" "@humanwhocodes/config-array" "^0.9.2" @@ -9754,12 +9754,12 @@ fragment-cache@^0.2.1: dependencies: map-cache "^0.2.2" -framer-motion@^6.4.3: - version "6.4.3" - resolved "https://registry.yarnpkg.com/framer-motion/-/framer-motion-6.4.3.tgz#1d60f352ccc2840b0302c35c0993d972da550d03" - integrity sha512-prcyOGFkGjwGEgbxObIWteVz1ihuWaDLdR03626cbA1GxTaPRpLb8ioJfWPmP5mwcWC7TlhMOjS5kBYnuiktFA== +framer-motion@^6.5.1: + version "6.5.1" + resolved "https://registry.yarnpkg.com/framer-motion/-/framer-motion-6.5.1.tgz#802448a16a6eb764124bf36d8cbdfa6dd6b931a7" + integrity sha512-o1BGqqposwi7cgDrtg0dNONhkmPsUFDaLcKXigzuTFC5x58mE8iyTazxSudFzmT6MEyJKfjjU8ItoMe3W+3fiw== dependencies: - "@motionone/dom" "^10.11.1" + "@motionone/dom" "10.12.0" framesync "6.0.1" hey-listen "^1.0.8" popmotion "11.0.3" @@ -14224,7 +14224,15 @@ postcss-lab-function@^4.2.0: "@csstools/postcss-progressive-custom-properties" "^1.1.0" postcss-value-parser "^4.2.0" -postcss-load-config@^4.0.0, postcss-load-config@^4.0.1: +postcss-load-config@^3.1.4: + version "3.1.4" + resolved "https://registry.yarnpkg.com/postcss-load-config/-/postcss-load-config-3.1.4.tgz#1ab2571faf84bb078877e1d07905eabe9ebda855" + integrity sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg== + dependencies: + lilconfig "^2.0.5" + yaml "^1.10.2" + +postcss-load-config@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/postcss-load-config/-/postcss-load-config-4.0.1.tgz#152383f481c2758274404e4962743191d73875bd" integrity sha512-vEJIc8RdiBRu3oRAI0ymerOn+7rPuMvRXslTvZUKZonDHFIczxztIyJ1urxM1x9JXEikvpWWTUUqal5j/8QgvA== @@ -17124,10 +17132,10 @@ synchronous-promise@^2.0.15: resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-2.0.15.tgz#07ca1822b9de0001f5ff73595f3d08c4f720eb8e" integrity sha512-k8uzYIkIVwmT+TcglpdN50pS2y1BDcUnBPK9iJeGu0Pl1lOI8pD6wtzgw91Pjpe+RxtTncw32tLxs/R0yNL2Mg== -tailwindcss@^3.0.2, tailwindcss@^3.1.5: - version "3.1.5" - resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.1.5.tgz#c8e0bb1cbacf29a6411d9c07debc1af9d388d4ca" - integrity sha512-bC/2dy3dGPqxMWAqFSRgQxVCfmO/31ZbeEp8s9DMDh4zgPZ5WW1gxRJkbBkXcTUIzaSUdhWrcsrSOe32ccgB4w== +tailwindcss@^3.0.2, tailwindcss@^3.1.6: + version "3.1.6" + resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.1.6.tgz#bcb719357776c39e6376a8d84e9834b2b19a49f1" + integrity sha512-7skAOY56erZAFQssT1xkpk+kWt2NrO45kORlxFPXUt3CiGsVPhH1smuH5XoDH6sGPXLyBv+zgCKA2HWBsgCytg== dependencies: arg "^5.0.2" chokidar "^3.5.3" @@ -17145,7 +17153,7 @@ tailwindcss@^3.0.2, tailwindcss@^3.1.5: postcss "^8.4.14" postcss-import "^14.1.0" postcss-js "^4.0.0" - postcss-load-config "^4.0.1" + postcss-load-config "^3.1.4" postcss-nested "5.0.6" postcss-selector-parser "^6.0.10" postcss-value-parser "^4.2.0" From 925d2e65bb2cf8da5c6934b76d2675b82e1ed903 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:28:39 +0000 Subject: [PATCH 11/19] :arrow_up: Bump gentype from 4.4.0 to 4.5.0 Bumps [gentype](https://github.com/cristianoc/gentype) from 4.4.0 to 4.5.0. - [Release notes](https://github.com/cristianoc/gentype/releases) - [Changelog](https://github.com/rescript-association/genType/blob/master/Changes.md) - [Commits](https://github.com/cristianoc/gentype/compare/v4.4.0...v4.5.0) --- updated-dependencies: - dependency-name: gentype dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- packages/squiggle-lang/package.json | 2 +- yarn.lock | 52 +++++++++++++++++------------ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/packages/squiggle-lang/package.json b/packages/squiggle-lang/package.json index b2067205..873bf6b7 100644 --- a/packages/squiggle-lang/package.json +++ b/packages/squiggle-lang/package.json @@ -54,7 +54,7 @@ "chalk": "^5.0.1", "codecov": "^3.8.3", "fast-check": "^3.0.1", - "gentype": "^4.4.0", + "gentype": "^4.5.0", "jest": "^27.5.1", "moduleserve": "^0.9.1", "nyc": "^15.1.0", diff --git a/yarn.lock b/yarn.lock index 62b18492..b451277f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2382,10 +2382,10 @@ resolved "https://registry.yarnpkg.com/@heroicons/react/-/react-1.0.6.tgz#35dd26987228b39ef2316db3b1245c42eb19e324" integrity sha512-JJCXydOFWMDpCP4q13iEplA503MQO3xLoZiKum+955ZCtHINWnx26CUxVxxFQu/uLb4LW3ge15ZpzIkXKkJ8oQ== -"@hookform/resolvers@^2.9.5": - version "2.9.5" - resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-2.9.5.tgz#adfa2d240a9315f4ab6ff4c63621d22d1b574c07" - integrity sha512-4XABrKdE4GpX6v2RZ+Ij1Wrl9qPEl5ZvVhFxROY+SZhP/6TU8gPw0LO4ZS9/GgIbTx3Pw1U8HmcXVAoGOq+7iA== +"@hookform/resolvers@^2.9.6": + version "2.9.6" + resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-2.9.6.tgz#db4277a96d1817d94169108167014926d8a10398" + integrity sha512-f4VxF8w9rdX0WsDCk3FW1dGPj/Sj8+1Ulcgtm5ymgWEpbA/fjY+NUDh+L9hftmxDgP8+EJFtF+qFK4gPEXVrVQ== "@humanwhocodes/config-array@^0.9.2": version "0.9.5" @@ -4535,10 +4535,10 @@ "@testing-library/dom" "^8.5.0" "@types/react-dom" "^18.0.0" -"@testing-library/user-event@^14.2.1": - version "14.2.1" - resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.2.1.tgz#8c5ff2d004544bb2220e1d864f7267fe7eb6c556" - integrity sha512-HOr1QiODrq+0j9lKU5i10y9TbhxMBMRMGimNx10asdmau9cb8Xb1Vyg0GvTwyIL2ziQyh2kAloOtAQFBQVuecA== +"@testing-library/user-event@^14.2.6": + version "14.2.6" + resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.2.6.tgz#9ba313a212994eea66e018520e23542ac3eb6fbe" + integrity sha512-l/4W4x3Lm24wkWNkPasXqvEzG+a6n2X872XCUjhyfbNqcoOapaWyCxC5Fz+E4r7JPu8gysQKSSCrK0OO2x+D+A== "@tootallnate/once@1": version "1.1.2" @@ -9091,10 +9091,10 @@ eslint-webpack-plugin@^3.1.1: normalize-path "^3.0.0" schema-utils "^3.1.1" -eslint@^8.19.0, eslint@^8.3.0: - version "8.19.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.19.0.tgz#7342a3cbc4fbc5c106a1eefe0fd0b50b6b1a7d28" - integrity sha512-SXOPj3x9VKvPe81TjjUJCYlV4oJjQw68Uek+AM0X4p+33dj2HY5bpTZOgnQHcG2eAm1mtCU9uNMnJi7exU/kYw== +eslint@^8.20.0, eslint@^8.3.0: + version "8.20.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.20.0.tgz#048ac56aa18529967da8354a478be4ec0a2bc81b" + integrity sha512-d4ixhz5SKCa1D6SCPrivP7yYVi7nyD6A4vs6HIAul9ujBzcEmZVM3/0NN/yu5nKhmO1wjp5xQ46iRfmDGlOviA== dependencies: "@eslint/eslintrc" "^1.3.0" "@humanwhocodes/config-array" "^0.9.2" @@ -9902,10 +9902,10 @@ gensync@^1.0.0-beta.1, gensync@^1.0.0-beta.2: resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0" integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg== -gentype@^4.4.0: - version "4.4.0" - resolved "https://registry.yarnpkg.com/gentype/-/gentype-4.4.0.tgz#20a61776703ce79c638c4db34b8808e1896d3267" - integrity sha512-hLcKmMhD3DJzHffDqwYUkEZfdGSWJk6ehYmdzGHBs35mTJa2dhiAp31WqmhjkZIqKvD+A+gFEE+//QHG5dZfwg== +gentype@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/gentype/-/gentype-4.5.0.tgz#460152da93db783626fd25bbd38fb574d886f5f3" + integrity sha512-XqHBQPS6Qb2HSgNJAwYRXbQJ4LSvz+MgNvuWnj8bz0teSorsy2kDxA6F1eZx5ft8cnfKAls4uNEgd5uNcPbQDg== get-caller-file@^2.0.1, get-caller-file@^2.0.5: version "2.0.5" @@ -14224,7 +14224,15 @@ postcss-lab-function@^4.2.0: "@csstools/postcss-progressive-custom-properties" "^1.1.0" postcss-value-parser "^4.2.0" -postcss-load-config@^4.0.0, postcss-load-config@^4.0.1: +postcss-load-config@^3.1.4: + version "3.1.4" + resolved "https://registry.yarnpkg.com/postcss-load-config/-/postcss-load-config-3.1.4.tgz#1ab2571faf84bb078877e1d07905eabe9ebda855" + integrity sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg== + dependencies: + lilconfig "^2.0.5" + yaml "^1.10.2" + +postcss-load-config@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/postcss-load-config/-/postcss-load-config-4.0.1.tgz#152383f481c2758274404e4962743191d73875bd" integrity sha512-vEJIc8RdiBRu3oRAI0ymerOn+7rPuMvRXslTvZUKZonDHFIczxztIyJ1urxM1x9JXEikvpWWTUUqal5j/8QgvA== @@ -17124,10 +17132,10 @@ synchronous-promise@^2.0.15: resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-2.0.15.tgz#07ca1822b9de0001f5ff73595f3d08c4f720eb8e" integrity sha512-k8uzYIkIVwmT+TcglpdN50pS2y1BDcUnBPK9iJeGu0Pl1lOI8pD6wtzgw91Pjpe+RxtTncw32tLxs/R0yNL2Mg== -tailwindcss@^3.0.2, tailwindcss@^3.1.5: - version "3.1.5" - resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.1.5.tgz#c8e0bb1cbacf29a6411d9c07debc1af9d388d4ca" - integrity sha512-bC/2dy3dGPqxMWAqFSRgQxVCfmO/31ZbeEp8s9DMDh4zgPZ5WW1gxRJkbBkXcTUIzaSUdhWrcsrSOe32ccgB4w== +tailwindcss@^3.0.2, tailwindcss@^3.1.6: + version "3.1.6" + resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.1.6.tgz#bcb719357776c39e6376a8d84e9834b2b19a49f1" + integrity sha512-7skAOY56erZAFQssT1xkpk+kWt2NrO45kORlxFPXUt3CiGsVPhH1smuH5XoDH6sGPXLyBv+zgCKA2HWBsgCytg== dependencies: arg "^5.0.2" chokidar "^3.5.3" @@ -17145,7 +17153,7 @@ tailwindcss@^3.0.2, tailwindcss@^3.1.5: postcss "^8.4.14" postcss-import "^14.1.0" postcss-js "^4.0.0" - postcss-load-config "^4.0.1" + postcss-load-config "^3.1.4" postcss-nested "5.0.6" postcss-selector-parser "^6.0.10" postcss-value-parser "^4.2.0" From 15d63a6a962545790e9e45490d097f319b760760 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 18 Jul 2022 18:31:09 +0200 Subject: [PATCH 12/19] type modifiers -> type contracts --- .../Reducer_Peggy/Reducer_Peggy_Parse_type_test.res | 6 +++--- .../Reducer_Peggy_ToExpression_type_test.res | 6 +++--- ...Type_Modifiers.res => Reducer_Type_Contracts.res} | 4 ++-- .../rescript/Reducer/Reducer_Type/Reducer_Type_T.res | 12 ++++++------ .../Reducer_Type/Reducer_Type_TypeChecker.res | 10 +++++----- 5 files changed, 19 insertions(+), 19 deletions(-) rename packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/{Reducer_Type_Modifiers.res => Reducer_Type_Contracts.res} (90%) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_type_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_type_test.res index f1dcd4bc..4f7dabdc 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_type_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_type_test.res @@ -20,7 +20,7 @@ describe("Peggy parse type", () => { "{(::$_typeOf_$ :f (::$_typeFunction_$ (::$_constructArray_$ (#number #number #number))))}", ) }) - describe("high priority modifier", () => { + describe("high priority contract", () => { testParse( "answer: number<-min<-max(100)|string", "{(::$_typeOf_$ :answer (::$_typeOr_$ (::$_constructArray_$ ((::$_typeModifier_max_$ (::$_typeModifier_min_$ #number) 100) #string))))}", @@ -30,7 +30,7 @@ describe("Peggy parse type", () => { "{(::$_typeOf_$ :answer (::$_typeModifier_memberOf_$ #number (::$_constructArray_$ (1 3 5))))}", ) }) - describe("low priority modifier", () => { + describe("low priority contract", () => { testParse( "answer: number | string $ opaque", "{(::$_typeOf_$ :answer (::$_typeModifier_opaque_$ (::$_typeOr_$ (::$_constructArray_$ (#number #string)))))}", @@ -70,7 +70,7 @@ describe("Peggy parse type", () => { "{(::$_typeOf_$ :answer (::$_typeModifier_opaque_$ (::$_typeOr_$ (::$_constructArray_$ (#number #string)))))}", ) }) - describe("squiggle expressions in type modifiers", () => { + describe("squiggle expressions in type contracts", () => { testParse( "odds1 = [1,3,5]; odds2 = [7, 9]; type odds = number<-memberOf(concat(odds1, odds2))", "{:odds1 = {(::$_constructArray_$ (1 3 5))}; :odds2 = {(::$_constructArray_$ (7 9))}; (::$_typeAlias_$ #odds (::$_typeModifier_memberOf_$ #number (::concat :odds1 :odds2)))}", diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_type_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_type_test.res index 12d2d62b..9849adb0 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_type_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_type_test.res @@ -40,7 +40,7 @@ describe("Peggy Types to Expression", () => { (), ) }) - describe("high priority modifier", () => { + describe("high priority contract", () => { testToExpression( "answer: number<-min(1)<-max(100)|string", "{(:$_typeOf_$ :answer (:$_typeOr_$ (:$_constructArray_$ ((:$_typeModifier_max_$ (:$_typeModifier_min_$ #number 1) 100) #string))))}", @@ -78,7 +78,7 @@ describe("Peggy Types to Expression", () => { (), ) }) - describe("low priority modifier", () => { + describe("low priority contract", () => { testToExpression( "answer: number | string $ opaque", "{(:$_typeOf_$ :answer (:$_typeModifier_opaque_$ (:$_typeOr_$ (:$_constructArray_$ (#number #string)))))}", @@ -86,7 +86,7 @@ describe("Peggy Types to Expression", () => { (), ) }) - describe("squiggle expressions in type modifiers", () => { + describe("squiggle expressions in type contracts", () => { testToExpression( "odds1 = [1,3,5]; odds2 = [7, 9]; type odds = number<-memberOf(concat(odds1, odds2))", "{(:$_let_$ :odds1 {(:$_constructArray_$ (1 3 5))}); (:$_let_$ :odds2 {(:$_constructArray_$ (7 9))}); (:$_typeAlias_$ #odds (:$_typeModifier_memberOf_$ #number (:concat :odds1 :odds2)))}", diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Modifiers.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Contracts.res similarity index 90% rename from packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Modifiers.res rename to packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Contracts.res index 457e97d8..7b68f178 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Modifiers.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Contracts.res @@ -41,10 +41,10 @@ let checkModifier = ( } let checkModifiers = ( - modifiers: Belt.Map.String.t, + contracts: Belt.Map.String.t, aValue: InternalExpressionValue.t, ): bool => { - modifiers->Belt.Map.String.reduce(true, (acc, key, modifierArg) => + contracts->Belt.Map.String.reduce(true, (acc, key, modifierArg) => switch acc { | true => checkModifier(key, modifierArg, aValue) | _ => acc diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res index d8011d23..511fe815 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_T.res @@ -3,7 +3,7 @@ open InternalExpressionValue type rec iType = | ItTypeIdentifier(string) - | ItModifiedType({modifiedType: iType, modifiers: Belt.Map.String.t}) + | ItModifiedType({modifiedType: iType, contracts: Belt.Map.String.t}) | ItTypeOr({typeOr: array}) | ItTypeFunction({inputs: array, output: iType}) | ItTypeArray({element: iType}) @@ -16,8 +16,8 @@ type typeErrorValue = TypeMismatch(t, InternalExpressionValue.t) let rec toString = (t: t): string => { switch t { | ItTypeIdentifier(s) => s - | ItModifiedType({modifiedType, modifiers}) => - `${toString(modifiedType)}${modifiers->Belt.Map.String.reduce("", (acc, k, v) => + | ItModifiedType({modifiedType, contracts}) => + `${toString(modifiedType)}${contracts->Belt.Map.String.reduce("", (acc, k, v) => Js.String2.concatMany(acc, ["<-", k, "(", InternalExpressionValue.toString(v), ")"]) )}` | ItTypeOr({typeOr}) => `(${Js.Array2.map(typeOr, toString)->Js.Array2.joinWith(" | ")})` @@ -82,7 +82,7 @@ let rec fromTypeMap = typeMap => { default, ) - let modifiers = + let contracts = typeMap->Belt.Map.String.keep((k, _v) => ["min", "max", "memberOf"]->Js.Array2.includes(k)) let makeIt = switch evTypeTag { @@ -96,9 +96,9 @@ let rec fromTypeMap = typeMap => { | _ => raise(Reducer_Exception.ImpossibleException("Reducer_Type_T-evTypeTag")) } - Belt.Map.String.isEmpty(modifiers) + Belt.Map.String.isEmpty(contracts) ? makeIt - : ItModifiedType({modifiedType: makeIt, modifiers: modifiers}) + : ItModifiedType({modifiedType: makeIt, contracts: contracts}) } and fromIEvValue = (ievValue: InternalExpressionValue.t): iType => diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res index 2778d3e4..e4336df5 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_TypeChecker.res @@ -1,7 +1,7 @@ module ExpressionT = Reducer_Expression_T module InternalExpressionValue = ReducerInterface_InternalExpressionValue module T = Reducer_Type_T -module TypeModifiers = Reducer_Type_Modifiers +module TypeContracts = Reducer_Type_Contracts open InternalExpressionValue let rec isITypeOf = (anIType: T.iType, aValue): result => { @@ -92,11 +92,11 @@ let rec isITypeOf = (anIType: T.iType, aValue): result = let caseModifiedType = ( anIType: T.iType, modifiedType: T.iType, - modifiers: Belt.Map.String.t, + contracts: Belt.Map.String.t, aValue: InternalExpressionValue.t, ) => { isITypeOf(modifiedType, aValue)->Belt.Result.flatMap(_result => { - if TypeModifiers.checkModifiers(modifiers, aValue) { + if TypeContracts.checkModifiers(contracts, aValue) { Ok(true) } else { T.TypeMismatch(anIType, aValue)->Error @@ -106,8 +106,8 @@ let rec isITypeOf = (anIType: T.iType, aValue): result = switch anIType { | ItTypeIdentifier(name) => caseTypeIdentifier(name, aValue) - | ItModifiedType({modifiedType, modifiers}) => - caseModifiedType(anIType, modifiedType, modifiers, aValue) //{modifiedType: iType, modifiers: Belt.Map.String.t} + | ItModifiedType({modifiedType, contracts}) => + caseModifiedType(anIType, modifiedType, contracts, aValue) //{modifiedType: iType, contracts: Belt.Map.String.t} | ItTypeOr({typeOr}) => caseOr(anIType, typeOr, aValue) | ItTypeFunction(_) => raise( From 6e1be862d2bcf1dd685ff830a52eab192832003b Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 18 Jul 2022 18:51:05 +0200 Subject: [PATCH 13/19] reducer passed to external library --- .../Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res | 3 +-- .../ReducerInterface/ReducerInterface_ExternalLibrary.res | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res index d0d88b2a..aa27d7ec 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res @@ -255,11 +255,10 @@ let dispatch = (call: functionCall, environment, reducer: ExpressionT.reducerFn) errorValue, > => try { - let callInternalWithReducer = (call, environment) => callInternal(call, environment, reducer) let (fn, args) = call // There is a bug that prevents string match in patterns // So we have to recreate a copy of the string - ExternalLibrary.dispatch((Js.String.make(fn), args), environment, callInternalWithReducer) + ExternalLibrary.dispatch((Js.String.make(fn), args), environment, reducer, callInternal) } catch { | Js.Exn.Error(obj) => REJavaScriptExn(Js.Exn.message(obj), Js.Exn.name(obj))->Error | _ => RETodo("unhandled rescript exception")->Error diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalLibrary.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalLibrary.res index 3e6172c9..2a479bb5 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalLibrary.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalLibrary.res @@ -23,7 +23,7 @@ let tryRegistry = ((fnName, args): InternalExpressionValue.functionCall, env) => ) } -let dispatch = (call: InternalExpressionValue.functionCall, environment, chain): result< +let dispatch = (call: InternalExpressionValue.functionCall, environment, reducer, chain): result< internalExpressionValue, 'e, > => { @@ -33,7 +33,7 @@ let dispatch = (call: InternalExpressionValue.functionCall, environment, chain): () => ReducerInterface_Duration.dispatch(call, environment), () => ReducerInterface_Number.dispatch(call, environment), () => tryRegistry(call, environment), - ])->E.O2.default(chain(call, environment)) + ])->E.O2.default(chain(call, environment, reducer)) } /* If your dispatch is too big you can divide it into smaller dispatches and pass the call so that it gets called finally. From 4535041876760f18bd80ef46f3832390cbd2c889 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 18 Jul 2022 22:52:19 +0200 Subject: [PATCH 14/19] less test clutter --- .../Reducer_Type_Compile_test.res | 36 ++++++--------- ...educer_Type_TypeChecker_arguments_test.res | 15 +------ .../Reducer_Type_TypeChecker_test.res | 44 ++++++++----------- 3 files changed, 33 insertions(+), 62 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res index 4de688d1..71f90373 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_Compile_test.res @@ -15,7 +15,7 @@ let myIevEvalToString = (aTypeSourceCode: string) => let myIevExpectEqual = (aTypeSourceCode, answer) => expect(myIevEvalToString(aTypeSourceCode))->toEqual(answer) -let _myIevTest = (test, aTypeSourceCode, answer) => +let myIevTest = (test, aTypeSourceCode, answer) => test(aTypeSourceCode, () => myIevExpectEqual(aTypeSourceCode, answer)) let myTypeEval = (aTypeSourceCode: string) => @@ -25,38 +25,28 @@ let myTypeEvalToString = (aTypeSourceCode: string) => myTypeEval(aTypeSourceCode let myTypeExpectEqual = (aTypeSourceCode, answer) => expect(myTypeEvalToString(aTypeSourceCode))->toEqual(answer) -let _myTypeTest = (test, aTypeSourceCode, answer) => +let myTypeTest = (test, aTypeSourceCode, answer) => test(aTypeSourceCode, () => myTypeExpectEqual(aTypeSourceCode, answer)) -let myIevTest = (aTypeSourceCode, answer) => _myIevTest(test, aTypeSourceCode, answer) -let myTypeTest = (aTypeSourceCode, answer) => _myTypeTest(test, aTypeSourceCode, answer) -module MySkip = { - let myIevTest = (aTypeSourceCode, answer) => _myIevTest(Skip.test, aTypeSourceCode, answer) - let myTypeTest = (aTypeSourceCode, answer) => _myTypeTest(Skip.test, aTypeSourceCode, answer) -} -module MyOnly = { - let myIevTest = (aTypeSourceCode, answer) => _myIevTest(Only.test, aTypeSourceCode, answer) - let myTypeTest = (aTypeSourceCode, answer) => _myTypeTest(Only.test, aTypeSourceCode, answer) -} - // | ItTypeIdentifier(string) -myTypeTest("number", "number") -myTypeTest("(number)", "number") +myTypeTest(test, "number", "number") +myTypeTest(test, "(number)", "number") // | ItModifiedType({modifiedType: iType}) -myIevTest("number<-min(0)", "Ok({min: 0,typeIdentifier: #number,typeTag: 'typeIdentifier'})") -myTypeTest("number<-min(0)", "number<-min(0)") +myIevTest(test, "number<-min(0)", "Ok({min: 0,typeIdentifier: #number,typeTag: 'typeIdentifier'})") +myTypeTest(test, "number<-min(0)", "number<-min(0)") // | ItTypeOr({typeOr: array}) -myTypeTest("number | string", "(number | string)") +myTypeTest(test, "number | string", "(number | string)") // | ItTypeFunction({inputs: array, output: iType}) -myTypeTest("number => number => number", "(number => number => number)") +myTypeTest(test, "number => number => number", "(number => number => number)") // | ItTypeArray({element: iType}) -myIevTest("[number]", "Ok({element: #number,typeTag: 'typeArray'})") -myTypeTest("[number]", "[number]") +myIevTest(test, "[number]", "Ok({element: #number,typeTag: 'typeArray'})") +myTypeTest(test, "[number]", "[number]") // | ItTypeTuple({elements: array}) -myTypeTest("[number, string]", "[number, string]") +myTypeTest(test, "[number, string]", "[number, string]") // | ItTypeRecord({properties: Belt.Map.String.t}) myIevTest( + test, "{age: number, name: string}", "Ok({properties: {age: #number,name: #string},typeTag: 'typeRecord'})", ) -myTypeTest("{age: number, name: string}", "{age: number, name: string}") +myTypeTest(test, "{age: number, name: string}", "{age: number, name: string}") diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res index 9c23e38e..07da15bb 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_arguments_test.res @@ -35,18 +35,7 @@ let myCheckArguments = (aTypeSourceCode: string, sourceCode: string): string => let myCheckArgumentsExpectEqual = (aTypeSourceCode, sourceCode, answer) => expect(myCheckArguments(aTypeSourceCode, sourceCode))->toEqual(answer) -let _myCheckArgumentsTest = (test, aTypeSourceCode, sourceCode, answer) => +let myCheckArgumentsTest = (test, aTypeSourceCode, sourceCode, answer) => test(aTypeSourceCode, () => myCheckArgumentsExpectEqual(aTypeSourceCode, sourceCode, answer)) -let myCheckArgumentsTest = (aTypeSourceCode, sourceCode, answer) => - _myCheckArgumentsTest(test, aTypeSourceCode, sourceCode, answer) -module MySkip = { - let myCheckArgumentsTest = (aTypeSourceCode, sourceCode, answer) => - _myCheckArgumentsTest(Skip.test, aTypeSourceCode, sourceCode, answer) -} -module MyOnly = { - let myCheckArgumentsTest = (aTypeSourceCode, sourceCode, answer) => - _myCheckArgumentsTest(Only.test, aTypeSourceCode, sourceCode, answer) -} - -myCheckArgumentsTest("number=>number=>number", "[1,2]", "Ok") +myCheckArgumentsTest(test, "number=>number=>number", "[1,2]", "Ok") diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res index d845d550..efd9bb18 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Type/Reducer_Type_TypeChecker_test.res @@ -33,46 +33,38 @@ let myTypeCheck = (aTypeSourceCode: string, sourceCode: string): string => let myTypeCheckExpectEqual = (aTypeSourceCode, sourceCode, answer) => expect(myTypeCheck(aTypeSourceCode, sourceCode))->toEqual(answer) -let _myTypeCheckTest = (test, aTypeSourceCode, sourceCode, answer) => +let myTypeCheckTest = (test, aTypeSourceCode, sourceCode, answer) => test(aTypeSourceCode, () => myTypeCheckExpectEqual(aTypeSourceCode, sourceCode, answer)) -let myTypeCheckTest = (aTypeSourceCode, sourceCode, answer) => - _myTypeCheckTest(test, aTypeSourceCode, sourceCode, answer) -module MySkip = { - let myTypeCheckTest = (aTypeSourceCode, sourceCode, answer) => - _myTypeCheckTest(Skip.test, aTypeSourceCode, sourceCode, answer) -} -module MyOnly = { - let myTypeCheckTest = (aTypeSourceCode, sourceCode, answer) => - _myTypeCheckTest(Only.test, aTypeSourceCode, sourceCode, answer) -} - -myTypeCheckTest("number", "1", "Ok") -myTypeCheckTest("number", "'2'", "Expected type: number but got: '2'") -myTypeCheckTest("string", "3", "Expected type: string but got: 3") -myTypeCheckTest("string", "'a'", "Ok") -myTypeCheckTest("[number]", "[1,2,3]", "Ok") -myTypeCheckTest("[number]", "['a','a','a']", "Expected type: number but got: 'a'") -myTypeCheckTest("[number]", "[1,'a',3]", "Expected type: number but got: 'a'") -myTypeCheckTest("[number, string]", "[1,'a']", "Ok") -myTypeCheckTest("[number, string]", "[1, 2]", "Expected type: string but got: 2") +myTypeCheckTest(test, "number", "1", "Ok") +myTypeCheckTest(test, "number", "'2'", "Expected type: number but got: '2'") +myTypeCheckTest(test, "string", "3", "Expected type: string but got: 3") +myTypeCheckTest(test, "string", "'a'", "Ok") +myTypeCheckTest(test, "[number]", "[1,2,3]", "Ok") +myTypeCheckTest(test, "[number]", "['a','a','a']", "Expected type: number but got: 'a'") +myTypeCheckTest(test, "[number]", "[1,'a',3]", "Expected type: number but got: 'a'") +myTypeCheckTest(test, "[number, string]", "[1,'a']", "Ok") +myTypeCheckTest(test, "[number, string]", "[1, 2]", "Expected type: string but got: 2") myTypeCheckTest( + test, "[number, string, string]", "[1,'a']", "Expected type: [number, string, string] but got: [1,'a']", ) myTypeCheckTest( + test, "[number, string]", "[1,'a', 3]", "Expected type: [number, string] but got: [1,'a',3]", ) -myTypeCheckTest("{age: number, name: string}", "{age: 1, name: 'a'}", "Ok") +myTypeCheckTest(test, "{age: number, name: string}", "{age: 1, name: 'a'}", "Ok") myTypeCheckTest( + test, "{age: number, name: string}", "{age: 1, name: 'a', job: 'IT'}", "Expected type: {age: number, name: string} but got: {age: 1,job: 'IT',name: 'a'}", ) -myTypeCheckTest("number | string", "1", "Ok") -myTypeCheckTest("date | string", "1", "Expected type: (date | string) but got: 1") -myTypeCheckTest("number<-min(10)", "10", "Ok") -myTypeCheckTest("number<-min(10)", "0", "Expected type: number<-min(10) but got: 0") +myTypeCheckTest(test, "number | string", "1", "Ok") +myTypeCheckTest(test, "date | string", "1", "Expected type: (date | string) but got: 1") +myTypeCheckTest(test, "number<-min(10)", "10", "Ok") +myTypeCheckTest(test, "number<-min(10)", "0", "Expected type: number<-min(10) but got: 0") From ffaf349e0aa2f998b023f4c112d4d93aa1032981 Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Tue, 19 Jul 2022 11:33:11 +1000 Subject: [PATCH 15/19] Basic mapSampleN support --- .../Reducer_Dispatch_BuiltIn_test.res | 4 +++ .../SampleSetDist/SampleSetDist.res | 5 ++++ .../Reducer_Dispatch_BuiltIn.res | 26 +++++++++++++++++-- .../squiggle-lang/src/rescript/Utility/E.res | 13 ++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res index 98192d31..65048ebb 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res @@ -21,6 +21,10 @@ describe("builtin", () => { "addOne(t)=t+1; toList(mapSamples(fromSamples([1,2,3,4,5,6]), addOne))", "Ok([2,3,4,5,6,7])", ) + testEval( + "toList(mapSamplesN([fromSamples([1,2,3,4,5,6]), fromSamples([6, 5, 4, 3, 2, 1])], {|x| x[0] > x[1] ? x[0] : x[1]}))", + "Ok([6,5,4,4,5,6])", + ) }) describe("builtin exception", () => { diff --git a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist.res b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist.res index bfbaa795..dc15f7a1 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist.res @@ -117,6 +117,11 @@ let map3 = ( ): result => E.A.zip3(get(t1), get(t2), get(t3))->E.A2.fmap(E.Tuple3.toFnCall(fn))->_fromSampleResultArray +let mapN = (~fn: array => result, ~t1: array): result< + t, + sampleSetError, +> => E.A.transpose(E.A.fmap(get, t1))->E.A2.fmap(fn)->_fromSampleResultArray + let mean = t => T.get(t)->E.A.Floats.mean let geomean = t => T.get(t)->E.A.Floats.geomean let mode = t => T.get(t)->E.A.Floats.mode diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res index 484b0acb..c7ab817e 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res @@ -19,6 +19,15 @@ open Reducer_ErrorValue exception TestRescriptException +let parseSampleSetArray = (arr: array): option> => { + let parseSampleSet = (value: internalExpressionValue): option => + switch value { + | IEvDistribution(SampleSet(dist)) => Some(dist) + | _ => None + } + E.A.O.openIfAllSome(E.A.fmap(parseSampleSet, arr)) +} + let callInternal = (call: functionCall, environment, reducer: ExpressionT.reducerFn): result< 'b, errorValue, @@ -149,6 +158,11 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce doLambdaCall(aLambdaValue, list{IEvNumber(a), IEvNumber(b), IEvNumber(c)}) SampleSetDist.map3(~fn, ~t1, ~t2, ~t3)->toType } + + let mapN = (t1: array, aLambdaValue) => { + let fn = a => doLambdaCall(aLambdaValue, list{IEvArray(E.A.fmap(x => IEvNumber(x), a))}) + SampleSetDist.mapN(~fn, ~t1)->toType + } } let doReduceArray = (aValueArray, initialValue, aLambdaValue) => { @@ -230,6 +244,12 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce ], ) => SampleMap.map3(dist1, dist2, dist3, aLambdaValue) + | ("mapSamplesN", [IEvArray(aValueArray), IEvLambda(aLambdaValue)]) => + switch parseSampleSetArray(aValueArray) { + | Some(sampleSetArr) => SampleMap.mapN(sampleSetArr, aLambdaValue) + | None => + Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) + } | ("reduce", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) => doReduceArray(aValueArray, initialValue, aLambdaValue) | ("reduceReverse", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) => @@ -246,7 +266,6 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) // Report full type signature as error } } - /* Reducer uses Result monad while reducing expressions */ @@ -262,5 +281,8 @@ let dispatch = (call: functionCall, environment, reducer: ExpressionT.reducerFn) ExternalLibrary.dispatch((Js.String.make(fn), args), environment, callInternalWithReducer) } catch { | Js.Exn.Error(obj) => REJavaScriptExn(Js.Exn.message(obj), Js.Exn.name(obj))->Error - | _ => RETodo("unhandled rescript exception")->Error + | err => { + Js.Console.log(err) + RETodo("unhandled rescript exception")->Error + } } diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index fd328a1c..f593cd48 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -631,6 +631,19 @@ module A = { ) let filter = Js.Array.filter let joinWith = Js.Array.joinWith + let transpose = (xs: array>): array> => { + let arr: array> = [] + for i in 0 to length(xs) - 1 { + for j in 0 to length(xs[i]) - 1 { + if Js.Array.length(arr) <= j { + ignore(Js.Array.push([xs[i][j]], arr)) + } else { + ignore(Js.Array.push(xs[i][j], arr[j])) + } + } + } + arr + } let all = (p: 'a => bool, xs: array<'a>): bool => length(filter(p, xs)) == length(xs) let any = (p: 'a => bool, xs: array<'a>): bool => length(filter(p, xs)) > 0 From 5bdc19f35f66986ed7f8b395ae547a99f90faba4 Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Tue, 19 Jul 2022 11:38:43 +1000 Subject: [PATCH 16/19] Refactor sampleN code and remove log --- .../Reducer_Dispatch_BuiltIn.res | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res index c7ab817e..40903521 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res @@ -19,15 +19,6 @@ open Reducer_ErrorValue exception TestRescriptException -let parseSampleSetArray = (arr: array): option> => { - let parseSampleSet = (value: internalExpressionValue): option => - switch value { - | IEvDistribution(SampleSet(dist)) => Some(dist) - | _ => None - } - E.A.O.openIfAllSome(E.A.fmap(parseSampleSet, arr)) -} - let callInternal = (call: functionCall, environment, reducer: ExpressionT.reducerFn): result< 'b, errorValue, @@ -159,9 +150,25 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce SampleSetDist.map3(~fn, ~t1, ~t2, ~t3)->toType } - let mapN = (t1: array, aLambdaValue) => { - let fn = a => doLambdaCall(aLambdaValue, list{IEvArray(E.A.fmap(x => IEvNumber(x), a))}) - SampleSetDist.mapN(~fn, ~t1)->toType + let mapN = (aValueArray: array, aLambdaValue) => { + switch parseSampleSetArray(aValueArray) { + | Some(t1) => + let fn = a => doLambdaCall(aLambdaValue, list{IEvArray(E.A.fmap(x => IEvNumber(x), a))}) + SampleSetDist.mapN(~fn, ~t1)->toType + | None => + Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) + } + } + + let parseSampleSetArray = (arr: array): option< + array, + > => { + let parseSampleSet = (value: internalExpressionValue): option => + switch value { + | IEvDistribution(SampleSet(dist)) => Some(dist) + | _ => None + } + E.A.O.openIfAllSome(E.A.fmap(parseSampleSet, arr)) } } @@ -245,11 +252,7 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce ) => SampleMap.map3(dist1, dist2, dist3, aLambdaValue) | ("mapSamplesN", [IEvArray(aValueArray), IEvLambda(aLambdaValue)]) => - switch parseSampleSetArray(aValueArray) { - | Some(sampleSetArr) => SampleMap.mapN(sampleSetArr, aLambdaValue) - | None => - Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) - } + SampleMap.mapN(aValueArray, aLambdaValue) | ("reduce", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) => doReduceArray(aValueArray, initialValue, aLambdaValue) | ("reduceReverse", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) => @@ -281,8 +284,5 @@ let dispatch = (call: functionCall, environment, reducer: ExpressionT.reducerFn) ExternalLibrary.dispatch((Js.String.make(fn), args), environment, callInternalWithReducer) } catch { | Js.Exn.Error(obj) => REJavaScriptExn(Js.Exn.message(obj), Js.Exn.name(obj))->Error - | err => { - Js.Console.log(err) - RETodo("unhandled rescript exception")->Error - } + | _ => RETodo("unhandled rescript exception")->Error } From 7887256ca10f5697d03e934866dbd5782cd502b8 Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Tue, 19 Jul 2022 11:45:07 +1000 Subject: [PATCH 17/19] Reorder function declarations to compile --- .../Reducer_Dispatch_BuiltIn.res | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res index 40903521..f0d8b3ab 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res @@ -150,16 +150,6 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce SampleSetDist.map3(~fn, ~t1, ~t2, ~t3)->toType } - let mapN = (aValueArray: array, aLambdaValue) => { - switch parseSampleSetArray(aValueArray) { - | Some(t1) => - let fn = a => doLambdaCall(aLambdaValue, list{IEvArray(E.A.fmap(x => IEvNumber(x), a))}) - SampleSetDist.mapN(~fn, ~t1)->toType - | None => - Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) - } - } - let parseSampleSetArray = (arr: array): option< array, > => { @@ -170,6 +160,16 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce } E.A.O.openIfAllSome(E.A.fmap(parseSampleSet, arr)) } + + let mapN = (aValueArray: array, aLambdaValue) => { + switch parseSampleSetArray(aValueArray) { + | Some(t1) => + let fn = a => doLambdaCall(aLambdaValue, list{IEvArray(E.A.fmap(x => IEvNumber(x), a))}) + SampleSetDist.mapN(~fn, ~t1)->toType + | None => + Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) + } + } } let doReduceArray = (aValueArray, initialValue, aLambdaValue) => { From 938b20b4cdb25f808a2aac3309661975b014cc65 Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Tue, 19 Jul 2022 12:38:05 +1000 Subject: [PATCH 18/19] Print error messages when functions fail --- .../src/components/FunctionChart.tsx | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/components/src/components/FunctionChart.tsx b/packages/components/src/components/FunctionChart.tsx index 05e4d393..73378cd8 100644 --- a/packages/components/src/components/FunctionChart.tsx +++ b/packages/components/src/components/FunctionChart.tsx @@ -1,5 +1,10 @@ import * as React from "react"; -import { lambdaValue, environment, runForeign } from "@quri/squiggle-lang"; +import { + lambdaValue, + environment, + runForeign, + errorValueToString, +} from "@quri/squiggle-lang"; import { FunctionChart1Dist } from "./FunctionChart1Dist"; import { FunctionChart1Number } from "./FunctionChart1Number"; import { DistributionPlottingSettings } from "./DistributionChart"; @@ -45,10 +50,16 @@ export const FunctionChart: React.FC = ({ } }; const validResult = getValidResult(); - const resultType = - validResult.tag === "Ok" ? validResult.value.tag : ("Error" as const); - switch (resultType) { + if (validResult.tag === "Error") { + return ( + + {errorValueToString(validResult.value)} + + ); + } + + switch (validResult.value.tag) { case "distribution": return ( = ({ height={height} /> ); - case "Error": - return ( - The function failed to be run - ); default: return ( There is no function visualization for this type of output:{" "} - {resultType} + {validResult.value.tag} ); } From 03edf60663126d6cdd4af76085ff1ed5630cf298 Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Tue, 19 Jul 2022 13:08:45 +1000 Subject: [PATCH 19/19] Show x coordinate when drawing discrete distributions --- packages/components/src/lib/distributionSpecBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/lib/distributionSpecBuilder.ts b/packages/components/src/lib/distributionSpecBuilder.ts index 7a5bcd2f..d04f0c44 100644 --- a/packages/components/src/lib/distributionSpecBuilder.ts +++ b/packages/components/src/lib/distributionSpecBuilder.ts @@ -223,7 +223,7 @@ export function buildVegaSpec( }, size: [{ value: 100 }], tooltip: { - signal: "datum.y", + signal: "{ probability: datum.y, value: datum.x }", }, }, update: {