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(