remove all type-related code

This commit is contained in:
Vyacheslav Matyukhin 2022-09-24 21:26:44 +04:00
parent c337211af6
commit d3bc08ab9d
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
20 changed files with 24 additions and 974 deletions

View File

@ -1,52 +0,0 @@
// module Expression = Reducer_Expression
// module Bindings = Reducer_Bindings
// module T = Reducer_Type_T
// module TypeCompile = Reducer_Type_Compile
// open Jest
// open Expect
// let myIevEval = (aTypeSourceCode: string) =>
// TypeCompile.ievFromTypeExpression(aTypeSourceCode, Expression.reduceExpressionInProject)
// let myIevEvalToString = (aTypeSourceCode: string) =>
// myIevEval(aTypeSourceCode)->Reducer_Value.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.reduceExpressionInProject)
// 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))
// // | ItTypeIdentifier(string)
// myTypeTest(test, "number", "number")
// myTypeTest(test, "(number)", "number")
// // | ItModifiedType({modifiedType: iType})
// myIevTest(test, "number<-min(0)", "Ok({min: 0,typeIdentifier: #number,typeTag: 'typeIdentifier'})")
// myTypeTest(test, "number<-min(0)", "number<-min(0)")
// // | ItTypeOr({typeOr: array<iType>})
// myTypeTest(test, "number | string", "(number | string)")
// // | ItTypeFunction({inputs: array<iType>, output: iType})
// myTypeTest(test, "number => number => number", "(number => number => number)")
// // | ItTypeArray({element: iType})
// myIevTest(test, "[number]", "Ok({element: #number,typeTag: 'typeArray'})")
// myTypeTest(test, "[number]", "[number]")
// // | ItTypeTuple({elements: array<iType>})
// myTypeTest(test, "[number, string]", "[number, string]")
// // | ItTypeRecord({properties: Belt.Map.String.t<iType>})
// myIevTest(
// test,
// "{age: number, name: string}",
// "Ok({properties: {age: #number,name: #string},typeTag: 'typeRecord'})",
// )
// myTypeTest(test, "{age: number, name: string}", "{age: number, name: string}")

View File

@ -1,41 +0,0 @@
// module Bindings = Reducer_Bindings
// module ErrorValue = Reducer_ErrorValue
// module Expression = Reducer_Expression
// module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
// 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.reduceExpressionInProject
// let rResult =
// Expression.BackCompatible.parse(sourceCode)->Belt.Result.map(expr =>
// reducerFn(expr, Bindings.emptyBindings, ProjectAccessorsT.identityAccessors)
// )
// 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))
// myCheckArgumentsTest(test, "number=>number=>number", "[1,2]", "Ok")

View File

@ -1,73 +0,0 @@
// module Expression = Reducer_Expression
// module ExpressionT = Reducer_Expression_T
// module ErrorValue = Reducer_ErrorValue
// module Bindings = Reducer_Bindings
// module T = Reducer_Type_T
// module TypeChecker = Reducer_Type_TypeChecker
// module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
// 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.reduceExpressionInProject
// let rResult =
// Expression.BackCompatible.parse(sourceCode)->Belt.Result.map(expr =>
// reducerFn(expr, Bindings.emptyBindings, ProjectAccessorsT.identityAccessors)
// )
// 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))
// 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(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(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")
// myTypeCheckTest(test, "any", "0", "Ok")
// myTypeCheckTest(test, "any", "'a'", "Ok")

View File

@ -1,125 +0,0 @@
// open Jest
// open Expect
// module DispatchT = Reducer_Dispatch_T
// module Expression = Reducer_Expression
// module ExpressionT = Reducer_Expression_T
// module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
// module TypeChecker = Reducer_Type_TypeChecker
// module TypeCompile = Reducer_Type_Compile
// type errorValue = Reducer_ErrorValue.errorValue
// // Let's build a function to replace switch statements
// // In dispatchChainPiece, we execute an return the result of execution if there is a type match.
// // Otherwise we return None so that the call chain can continue.
// // So we want to build a function like
// // dispatchChainPiece = (call: functionCall, accessors): option<result<Reducer_T.value, errorValue>>
// // Use accessors.environment to get the environment finally.
// // Now lets make the dispatchChainPiece itself.
// // Note that I am not passing the reducer to the dispatchChainPiece as an argument because it is in the context anyway.
// // Keep in mind that reducerFn is necessary for map/reduce so dispatchChainPiece should have a reducerFn in context.
// let makeMyDispatchChainPiece = (reducer: Reducer_T.reducerFn): DispatchT.dispatchChainPiece => {
// // Let's have a pure implementations
// module Implementation = {
// let stringConcat = (a: string, b: string): string => Js.String2.concat(a, b)
// let arrayConcat = (
// a: Js.Array2.t<Reducer_T.value>,
// b: Js.Array2.t<Reducer_T.value>,
// ): Js.Array2.t<Reducer_T.value> => Js.Array2.concat(a, b)
// let plot = _r => "yey, plotted"
// }
// let extractStringString = args =>
// switch args {
// | [IEvString(a), IEvString(b)] => (a, b)
// | _ => raise(Reducer_Exception.ImpossibleException("extractStringString developer error"))
// }
// let extractArrayArray = args =>
// switch args {
// | [IEvArray(a), IEvArray(b)] => (a, b)
// | _ => raise(Reducer_Exception.ImpossibleException("extractArrayArray developer error"))
// }
// // Let's bridge the pure implementation to expression values
// module Bridge = {
// let stringConcat: DispatchT.genericIEvFunction = (args, _accessors: ProjectAccessorsT.t) => {
// let (a, b) = extractStringString(args)
// Implementation.stringConcat(a, b)->IEvString->Ok
// }
// let arrayConcat: DispatchT.genericIEvFunction = (args, _accessors: ProjectAccessorsT.t) => {
// let (a, b) = extractArrayArray(args)
// Implementation.arrayConcat(a, b)->IEvArray->Ok
// }
// let plot: DispatchT.genericIEvFunction = (args, _accessors: ProjectAccessorsT.t) => {
// switch args {
// // Just assume that we are doing the business of extracting and converting the deep record
// | [IEvRecord(_)] => Implementation.plot({"title": "This is a plot"})->IEvString->Ok
// | _ => raise(Reducer_Exception.ImpossibleException("plot developer error"))
// }
// }
// }
// // concat functions are to illustrate polymoprhism. And the plot function is to illustrate complex types
// let jumpTable = [
// (
// "concat",
// TypeCompile.fromTypeExpressionExn("string=>string=>string", reducer),
// Bridge.stringConcat,
// ),
// (
// "concat",
// TypeCompile.fromTypeExpressionExn("[any]=>[any]=>[any]", reducer),
// Bridge.arrayConcat,
// ),
// (
// "plot",
// TypeCompile.fromTypeExpressionExn(
// // Nested complex types are available
// // records {property: type}
// // arrays [type]
// // tuples [type, type]
// // <- type contracts are available naturally and they become part of dispatching
// // Here we are not enumerating the possibilities because type checking has a dedicated test
// "{title: string, line: {width: number, color: string}}=>string",
// reducer,
// ),
// Bridge.plot,
// ),
// ]
// //Here we are creating a dispatchChainPiece function that will do the actual dispatch from the jumpTable
// Reducer_Dispatch_ChainPiece.makeFromTypes(jumpTable)
// }
// // And finally, let's write a library dispatch for our external library
// // Exactly the same as the one used in real life
// let _dispatch = (
// call: functionCall,
// accessors: ProjectAccessorsT.t,
// reducer: Reducer_T.reducerFn,
// chain,
// ): result<Reducer_T.value, 'e> => {
// let dispatchChainPiece = makeMyDispatchChainPiece(reducer)
// dispatchChainPiece(call, accessors)->E.O2.defaultFn(() => chain(call, accessors, reducer))
// }
// // What is important about this implementation?
// // A) Exactly the same function jump table can be used to create type guarded lambda functions
// // Guarded lambda functions will be the basis of the next version of Squiggle
// // B) Complicated recursive record types are not a problem.
// describe("Type Dispatch", () => {
// let reducerFn = Expression.reduceExpressionInProject
// let dispatchChainPiece = makeMyDispatchChainPiece(reducerFn)
// test("stringConcat", () => {
// let call: functionCall = ("concat", [IEvString("hello"), IEvString("world")])
// let result = dispatchChainPiece(call, ProjectAccessorsT.identityAccessors)
// expect(result)->toEqual(Some(Ok(IEvString("helloworld"))))
// })
// })

View File

@ -1,7 +0,0 @@
import * as RSType from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Type.gen";
type T = RSType.squiggleValue_Type;
export class SqType {
constructor(private _value: T) {}
}

View File

@ -5,7 +5,6 @@ import { SqLambda } from "./SqLambda";
import { SqLambdaDeclaration } from "./SqLambdaDeclaration";
import { SqRecord } from "./SqRecord";
import { SqArray } from "./SqArray";
import { SqType } from "./SqType";
import { SqValueLocation } from "./SqValueLocation";
export { Tag as SqValueTag };
@ -116,22 +115,6 @@ export class SqTimeDurationValue extends SqAbstractValue {
}
}
export class SqTypeValue extends SqAbstractValue {
tag = Tag.Type as const;
get value() {
return new SqType(this.valueMethod(RSValue.getType));
}
}
export class SqTypeIdentifierValue extends SqAbstractValue {
tag = Tag.TypeIdentifier as const;
get value() {
return this.valueMethod(RSValue.getTypeIdentifier);
}
}
export class SqVoidValue extends SqAbstractValue {
tag = Tag.Void as const;
@ -151,8 +134,6 @@ const tagToClass = {
[Tag.Record]: SqRecordValue,
[Tag.String]: SqStringValue,
[Tag.TimeDuration]: SqTimeDurationValue,
[Tag.Type]: SqTypeValue,
[Tag.TypeIdentifier]: SqTypeIdentifierValue,
[Tag.Void]: SqVoidValue,
} as const;
@ -169,6 +150,4 @@ export type SqValue =
| SqRecordValue
| SqStringValue
| SqTimeDurationValue
| SqTypeValue
| SqTypeIdentifierValue
| SqVoidValue;

View File

@ -3,7 +3,6 @@ type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use
@genType type squiggleValue_Array = Reducer_T.arrayValue //re-export recursive type
@genType type squiggleValue_Record = Reducer_T.map //re-export recursive type
@genType type squiggleValue_Type = Reducer_T.map //re-export recursive type
type squiggleValue_Declaration = ForTS_SquiggleValue_Declaration.squiggleValue_Declaration //use
type squiggleValue_Distribution = ForTS_SquiggleValue_Distribution.squiggleValue_Distribution //use
type squiggleValue_Lambda = ForTS_SquiggleValue_Lambda.squiggleValue_Lambda //use
@ -40,12 +39,6 @@ external svtString_: string = "String"
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
external svtTimeDuration_: string = "TimeDuration"
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
external svtType_: string = "Type"
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
external svtTypeIdentifier_: string = "TypeIdentifier"
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
external svtVoid_: string = "Void"
@ -67,8 +60,6 @@ let getTag = (variant: squiggleValue): squiggleValueTag =>
| IEvRecord(_) => svtRecord_->castEnum
| IEvString(_) => svtString_->castEnum
| IEvTimeDuration(_) => svtTimeDuration_->castEnum
| IEvType(_) => svtType_->castEnum
| IEvTypeIdentifier(_) => svtTypeIdentifier_->castEnum
| IEvVoid => svtVoid_->castEnum
}
@ -151,17 +142,3 @@ let getTimeDuration = (variant: squiggleValue): option<float> =>
| IEvTimeDuration(value) => value->Some
| _ => None
}
@genType
let getType = (variant: squiggleValue): option<squiggleValue_Type> =>
switch variant {
| IEvType(value) => value->Some
| _ => None
}
@genType
let getTypeIdentifier = (variant: squiggleValue): option<string> =>
switch variant {
| IEvTypeIdentifier(value) => value->Some
| _ => None
}

View File

@ -1,9 +0,0 @@
type squiggleValue = ForTS_SquiggleValue.squiggleValue //use
@genType type squiggleValue_Type = ForTS_SquiggleValue.squiggleValue_Type //re-export recursive type
@genType
let getKeyValuePairs = (value: squiggleValue_Type): array<(string, squiggleValue)> =>
Reducer_Value.recordToKeyValuePairs(value)
@genType
let toString = (value: squiggleValue_Type): string => Reducer_Value.toStringType(value)

View File

@ -9,7 +9,5 @@ export enum squiggleValueTag {
Record = "Record",
String = "String",
TimeDuration = "TimeDuration",
Type = "Type",
TypeIdentifier = "TypeIdentifier",
Void = "Void",
}

View File

@ -7,7 +7,6 @@
@genType type squiggleValue_Declaration = ForTS_SquiggleValue_Declaration.squiggleValue_Declaration //re-export
@genType type squiggleValue_Lambda = ForTS_SquiggleValue_Lambda.squiggleValue_Lambda //re-export
@genType type squiggleValue_Record = ForTS_SquiggleValue_Record.squiggleValue_Record //re-export
@genType type squiggleValue_Type = ForTS_SquiggleValue_Type.squiggleValue_Type //re-export
/* Distribution related */
@genType type squiggleValue_Distribution = ForTS_Distribution.distribution //re-export

View File

@ -45,44 +45,3 @@ let removeResult = ({namespace} as bindings: t): t => {
let locals = ({namespace}: t): Reducer_T.namespace => namespace
let fromNamespace = (namespace: Reducer_Namespace.t): t => {namespace: namespace, parent: None}
// let typeAliasesKey = "_typeAliases_"
// let typeReferencesKey = "_typeReferences_"
// let getType = (NameSpace(container): t, id: string) => {
// Belt.Map.String.get(container, typeAliasesKey)->Belt.Option.flatMap(aliases =>
// switch aliases {
// | IEvRecord(r) => Belt.Map.String.get(r, id)
// | _ => None
// }
// )
// }
// let getTypeOf = (NameSpace(container): t, id: string) => {
// Belt.Map.String.get(container, typeReferencesKey)->Belt.Option.flatMap(defs =>
// switch defs {
// | IEvRecord(r) => Belt.Map.String.get(r, id)
// | _ => None
// }
// )
// }
// let setTypeAlias = (NameSpace(container): t, id: string, value): t => {
// let rValue = Belt.Map.String.getWithDefault(container, typeAliasesKey, IEvRecord(emptyMap))
// let r = switch rValue {
// | IEvRecord(r) => r
// | _ => emptyMap
// }
// let r2 = Belt.Map.String.set(r, id, value)->IEvRecord
// NameSpace(Belt.Map.String.set(container, typeAliasesKey, r2))
// }
// let setTypeOf = (NameSpace(container): t, id: string, value): t => {
// let rValue = Belt.Map.String.getWithDefault(container, typeReferencesKey, IEvRecord(emptyMap))
// let r = switch rValue {
// | IEvRecord(r) => r
// | _ => emptyMap
// }
// let r2 = Belt.Map.String.set(r, id, value)->IEvRecord
// NameSpace(Belt.Map.String.set(container, typeReferencesKey, r2))
// }

View File

@ -1,24 +1,27 @@
// module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
// module T = Reducer_Dispatch_T
// module TypeChecker = Reducer_Type_TypeChecker
// open Reducer_Value
// types are disabled until review and rewrite for 0.5 interpreter compatibility
/*
module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
module T = Reducer_Dispatch_T
module TypeChecker = Reducer_Type_TypeChecker
open Reducer_Value
// type errorValue = Reducer_ErrorValue.errorValue
type errorValue = Reducer_ErrorValue.errorValue
// let makeFromTypes = jumpTable => {
// let dispatchChainPiece: T.dispatchChainPiece = (
// (fnName, fnArgs): functionCall,
// accessors: ProjectAccessorsT.t,
// ) => {
// let jumpTableEntry = jumpTable->Js.Array2.find(elem => {
// let (candidName, candidType, _) = elem
// candidName == fnName && TypeChecker.checkITypeArgumentsBool(candidType, fnArgs)
// })
// switch jumpTableEntry {
// | Some((_, _, bridgeFn)) => bridgeFn(fnArgs, accessors)->Some
// | _ => None
// }
// }
// dispatchChainPiece
// }
let makeFromTypes = jumpTable => {
let dispatchChainPiece: T.dispatchChainPiece = (
(fnName, fnArgs): functionCall,
accessors: ProjectAccessorsT.t,
) => {
let jumpTableEntry = jumpTable->Js.Array2.find(elem => {
let (candidName, candidType, _) = elem
candidName == fnName && TypeChecker.checkITypeArgumentsBool(candidType, fnArgs)
})
switch jumpTableEntry {
| Some((_, _, bridgeFn)) => bridgeFn(fnArgs, accessors)->Some
| _ => None
}
}
dispatchChainPiece
}
*/

View File

@ -37,7 +37,6 @@ array_statements
statement
= letStatement
/ defunStatement
// / typeStatement
/ voidStatement
voidStatement
@ -323,81 +322,3 @@ statementSeparator 'statement separator'
newLine "newline"
= [\n\r]
// // Types
// noArguments = ('(' _nl ')' )?
// typeIdentifier 'type identifier'
// = ([a-z]+[_a-z0-9]i*) {return h.nodeTypeIdentifier(text())}
// typeConstructorIdentifier 'type constructor identifier'
// = ([A-Z]+[_a-z0-9]i*) {return h.nodeTypeIdentifier(text())}
// typeExpression = typePostModifierExpression
// typePostModifierExpression = head:typeOr tail:(_ '$' _nl @typeModifier)*
// {
// return tail.reduce((result, element) => {
// return h.makeFunctionCall('$_typeModifier_'+element.modifier.value+'_$', [result, ...element.args])
// }, head)
// }
// typeOr = head:typeFunction tail:(_ '|' _nl @typeFunction)*
// { return tail.length === 0 ? head : h.makeFunctionCall('$_typeOr_$', [h.constructArray([head, ...tail])]); }
// typeFunction = head:typeModifierExpression tail:(_ '=>' _nl @typeModifierExpression)*
// { return tail.length === 0 ? head : h.makeFunctionCall( '$_typeFunction_$', [h.constructArray([head, ...tail])]); }
// typeModifierExpression = head:basicType tail:(_ '<-' _nl @typeModifier)*
// {
// return tail.reduce((result, element) => {
// return h.makeFunctionCall('$_typeModifier_'+element.modifier.value+'_$', [result, ...element.args])
// }, head)
// }
// typeModifier
// = modifier:identifier _ '(' _nl args:array_elements _nl ')'
// { return {modifier: modifier, args: args}; }
// / modifier:identifier _ noArguments
// { return {modifier: modifier, args: []}; }
// basicType = typeConstructor / typeArray / typeTuple / typeRecord / typeInParanthesis / typeIdentifier
// typeArray = '[' _nl elem:typeExpression _nl ']'
// {return h.makeFunctionCall('$_typeArray_$', [elem])}
// typeTuple = '[' _nl elems:array_typeTupleArguments _nl ']'
// { return h.makeFunctionCall('$_typeTuple_$', [h.constructArray(elems)])}
// array_typeTupleArguments
// = head:typeExpression tail:(_ ',' _nl @typeExpression)*
// { return [head, ...tail]; }
// typeRecord = '{' _nl elems:array_typeRecordArguments _nl '}'
// { return h.makeFunctionCall('$_typeRecord_$', [h.constructRecord(elems)]); }
// array_typeRecordArguments
// = head:typeKeyValuePair tail:(_ ',' _nl @typeKeyValuePair)*
// { return [head, ...tail]; }
// typeKeyValuePair
// = key:identifier _ ':' _nl value:typeExpression
// { return h.nodeKeyValue(key, value)}
// typeConstructor
// = constructor:typeConstructorIdentifier _ '(' _nl args:array_types _nl ')'
// { return h.makeFunctionCall('$_typeConstructor_$', [constructor, h.constructArray(args)]); }
// / constructor:typeConstructorIdentifier _ noArguments
// { return h.makeFunctionCall('$_typeConstructor_$', [constructor, h.constructArray([])]); }
// array_types = head:typeExpression tail:(_ ',' _nl @typeExpression)*
// { return [head, ...tail]; }
// typeStatement = typeAliasStatement / typeOfStatement
// typeAliasStatement = 'type' __nl typeIdentifier:typeIdentifier _nl '=' _nl typeExpression:typeExpression
// { return h.makeFunctionCall('$_typeAlias_$', [typeIdentifier, typeExpression])}
// typeOfStatement = identifier:identifier _ ':' _nl typeExpression:typeExpression
// { return h.makeFunctionCall('$_typeOf_$', [identifier, typeExpression])}
// typeInParanthesis = '(' _nl typeExpression:typeExpression _nl ')' {return typeExpression}

View File

@ -12,8 +12,6 @@ type rec value =
| IEvRecord(map)
| IEvString(string)
| IEvTimeDuration(float)
| IEvType(map)
| IEvTypeIdentifier(string)
| IEvVoid
@genType.opaque and arrayValue = array<value>
@genType.opaque and map = Belt.Map.String.t<value>

View File

@ -1,39 +0,0 @@
// module Bindings = Reducer_Bindings
// module ErrorValue = Reducer_ErrorValue
// module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
// module T = Reducer_Type_T
// let ievFromTypeExpression = (
// typeExpressionSourceCode: string,
// reducerFn: ProjectReducerFnT.t,
// ): result<Reducer_Value.t, ErrorValue.t> => {
// let sIndex = "compiled"
// let sourceCode = `type ${sIndex}=${typeExpressionSourceCode}`
// Reducer_Expression.BackCompatible.parse(sourceCode)->Belt.Result.flatMap(expr => {
// let accessors = ProjectAccessorsT.identityAccessors
// let _result = reducerFn(expr, Bindings.emptyBindings, accessors)
// let nameSpace = accessors.states.continuation
// switch Bindings.getType(nameSpace, sIndex) {
// | Some(value) => value->Ok
// | None => raise(Reducer_Exception.ImpossibleException("Reducer_Type_Compile-none"))
// }
// })
// }
// let fromTypeExpression = (typeExpressionSourceCode: string, reducerFn: Reducer_T.reducerFn): result<
// T.t,
// ErrorValue.t,
// > => {
// ievFromTypeExpression(typeExpressionSourceCode, reducerFn)->Belt.Result.map(T.fromIEvValue)
// }
// let fromTypeExpressionExn = (
// typeExpressionSourceCode: string,
// reducerFn: Reducer_T.reducerFn,
// ): T.t =>
// switch fromTypeExpression(typeExpressionSourceCode, reducerFn) {
// | Ok(value) => value
// | _ => `Cannot compile ${typeExpressionSourceCode}`->Reducer_Exception.ImpossibleException->raise
// }

View File

@ -1,45 +0,0 @@
module T = Reducer_Type_T
let isMin = (modifierArg: Reducer_Value.t, aValue: Reducer_Value.t): bool => {
let pair = (modifierArg, aValue)
switch pair {
| (IEvNumber(a), IEvNumber(b)) => a <= b
| _ => false
}
}
let isMax = (modifierArg: Reducer_Value.t, aValue: Reducer_Value.t): bool => {
let pair = (modifierArg, aValue)
switch pair {
| (IEvNumber(a), IEvNumber(b)) => a >= b
| _ => false
}
}
let isMemberOf = (modifierArg: Reducer_Value.t, aValue: Reducer_Value.t): bool => {
let pair = (modifierArg, aValue)
switch pair {
| (ievA, IEvArray(b)) => Js.Array2.includes(b, ievA)
| _ => false
}
}
let checkModifier = (key: string, modifierArg: Reducer_Value.t, aValue: Reducer_Value.t): bool =>
switch key {
| "min" => isMin(modifierArg, aValue)
| "max" => isMax(modifierArg, aValue)
| "isMemberOf" => isMemberOf(modifierArg, aValue)
| _ => false
}
let checkModifiers = (
contracts: Belt.Map.String.t<Reducer_Value.t>,
aValue: Reducer_Value.t,
): bool => {
contracts->Belt.Map.String.reduce(true, (acc, key, modifierArg) =>
switch acc {
| true => checkModifier(key, modifierArg, aValue)
| _ => acc
}
)
}

View File

@ -1,117 +0,0 @@
// type rec iType =
// | ItTypeIdentifier(string)
// | ItModifiedType({modifiedType: iType, contracts: Belt.Map.String.t<Reducer_Value.t>})
// | ItTypeOr({typeOr: array<iType>})
// | ItTypeFunction({inputs: array<iType>, output: iType})
// | ItTypeArray({element: iType})
// | ItTypeTuple({elements: array<iType>})
// | ItTypeRecord({properties: Belt.Map.String.t<iType>})
// type t = iType
// type typeErrorValue = TypeMismatch(t, Reducer_Value.t)
// let rec toString = (t: t): string => {
// switch t {
// | ItTypeIdentifier(s) => s
// | ItModifiedType({modifiedType, contracts}) =>
// `${toString(modifiedType)}${contracts->Belt.Map.String.reduce("", (acc, k, v) =>
// Js.String2.concatMany(acc, ["<-", k, "(", Reducer_Value.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<t, ErrorValue.t>) =>
// switch rt {
// | Ok(t) => toString(t)
// | Error(e) => ErrorValue.errorToString(e)
// }
// let rec fromTypeMap = typeMap => {
// let default = IEvString("")
// let evTypeTag: Reducer_Value.t = Belt.Map.String.getWithDefault(
// typeMap,
// "typeTag",
// default,
// )
// let evTypeIdentifier: Reducer_Value.t = Belt.Map.String.getWithDefault(
// typeMap,
// "typeIdentifier",
// default,
// )
// let evTypeOr: Reducer_Value.t = Belt.Map.String.getWithDefault(
// typeMap,
// "typeOr",
// default,
// )
// let evInputs: Reducer_Value.t = Belt.Map.String.getWithDefault(
// typeMap,
// "inputs",
// default,
// )
// let evOutput: Reducer_Value.t = Belt.Map.String.getWithDefault(
// typeMap,
// "output",
// default,
// )
// let evElement: Reducer_Value.t = Belt.Map.String.getWithDefault(
// typeMap,
// "element",
// default,
// )
// let evElements: Reducer_Value.t = Belt.Map.String.getWithDefault(
// typeMap,
// "elements",
// default,
// )
// let evProperties: Reducer_Value.t = Belt.Map.String.getWithDefault(
// typeMap,
// "properties",
// default,
// )
// let contracts =
// 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("Reducer_Type_T-evTypeTag"))
// }
// Belt.Map.String.isEmpty(contracts)
// ? makeIt
// : ItModifiedType({modifiedType: makeIt, contracts: contracts})
// }
// and fromIEvValue = (ievValue: Reducer_Value.t): iType =>
// switch ievValue {
// | IEvTypeIdentifier(typeIdentifier) => ItTypeIdentifier({typeIdentifier})
// | IEvType(typeMap) => fromTypeMap(typeMap)
// | _ => raise(Reducer_Exception.ImpossibleException("Reducer_Type_T-ievValue"))
// }
// and fromIEvArray = (ievArray: Reducer_Value.t) =>
// switch ievArray {
// | IEvArray(array) => array->Belt.Array.map(fromIEvValue)
// | _ => raise(Reducer_Exception.ImpossibleException("Reducer_Type_T-ievArray"))
// }
// and fromIEvRecord = (ievRecord: Reducer_Value.t) =>
// switch ievRecord {
// | IEvRecord(record) => record->Belt.Map.String.map(fromIEvValue)
// | _ => raise(Reducer_Exception.ImpossibleException("Reducer_Type_T-ievRecord"))
// }

View File

@ -1,81 +0,0 @@
// open ReducerInterface_InternalExpressionValue
// let typeModifier_memberOf = (aType, anArray) => {
// let newRecord = Belt.Map.String.fromArray([
// ("typeTag", IEvString("typeIdentifier")),
// ("typeIdentifier", aType),
// ])
// newRecord->Belt.Map.String.set("memberOf", anArray)->IEvType->Ok
// }
// let typeModifier_memberOf_update = (aRecord, anArray) => {
// aRecord->Belt.Map.String.set("memberOf", anArray)->IEvType->Ok
// }
// let typeModifier_min = (aType, value) => {
// let newRecord = Belt.Map.String.fromArray([
// ("typeTag", IEvString("typeIdentifier")),
// ("typeIdentifier", aType),
// ])
// newRecord->Belt.Map.String.set("min", value)->IEvType->Ok
// }
// let typeModifier_min_update = (aRecord, value) => {
// aRecord->Belt.Map.String.set("min", value)->IEvType->Ok
// }
// let typeModifier_max = (aType, value) => {
// let newRecord = Belt.Map.String.fromArray([
// ("typeTag", IEvString("typeIdentifier")),
// ("typeIdentifier", aType),
// ])
// newRecord->Belt.Map.String.set("max", value)->IEvType->Ok
// }
// let typeModifier_max_update = (aRecord, value) =>
// aRecord->Belt.Map.String.set("max", value)->IEvType->Ok
// let typeModifier_opaque_update = aRecord =>
// aRecord->Belt.Map.String.set("opaque", IEvBool(true))->IEvType->Ok
// let typeOr = evArray => {
// let newRecord = Belt.Map.String.fromArray([("typeTag", IEvString("typeOr")), ("typeOr", evArray)])
// newRecord->IEvType->Ok
// }
// let typeFunction = anArray => {
// let output = Belt.Array.getUnsafe(anArray, Js.Array2.length(anArray) - 1)
// let inputs = Js.Array2.slice(anArray, ~start=0, ~end_=-1)
// let newRecord = Belt.Map.String.fromArray([
// ("typeTag", IEvString("typeFunction")),
// ("inputs", IEvArray(inputs)),
// ("output", output),
// ])
// newRecord->IEvType->Ok
// }
// let typeArray = element => {
// let newRecord = Belt.Map.String.fromArray([
// ("typeTag", IEvString("typeArray")),
// ("element", element),
// ])
// newRecord->IEvType->Ok
// }
// let typeTuple = anArray => {
// let newRecord = Belt.Map.String.fromArray([
// ("typeTag", IEvString("typeTuple")),
// ("elements", IEvArray(anArray)),
// ])
// newRecord->IEvType->Ok
// }
// let typeRecord = propertyMap => {
// let newProperties = propertyMap->IEvRecord
// let newRecord = Belt.Map.String.fromArray([
// ("typeTag", IEvString("typeRecord")),
// ("properties", newProperties),
// ])
// newRecord->IEvType->Ok
// }

View File

@ -1,181 +0,0 @@
// module ExpressionT = Reducer_Expression_T
// module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
// module T = Reducer_Type_T
// module TypeContracts = Reducer_Type_Contracts
// open Reducer_Value
// let rec isITypeOf = (anIType: T.iType, aValue): result<bool, T.typeErrorValue> => {
// let caseTypeIdentifier = (anUpperTypeName, aValue) => {
// let aTypeName = anUpperTypeName->Js.String2.toLowerCase
// switch aTypeName {
// | "any" => Ok(true)
// | _ => {
// let valueTypeName = aValue->valueToValueType->valueTypeToString->Js.String2.toLowerCase
// switch aTypeName == valueTypeName {
// | true => Ok(true)
// | false => T.TypeMismatch(anIType, aValue)->Error
// }
// }
// }
// }
// let caseRecord = (anIType, propertyMap: Belt.Map.String.t<T.iType>, 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 acc {
// | Ok(false) =>
// switch isITypeOf(anIType, evValue) {
// | Ok(_) => Ok(true)
// | Error(_) => acc
// }
// | _ => acc
// }
// )
// ) {
// | Ok(true) => Ok(true)
// | Ok(false) => T.TypeMismatch(anIType, evValue)->Error
// | Error(error) => Error(error)
// }
// let caseModifiedType = (
// anIType: T.iType,
// modifiedType: T.iType,
// contracts: Belt.Map.String.t<Reducer_Value.t>,
// aValue: Reducer_Value.t,
// ) => {
// isITypeOf(modifiedType, aValue)->Belt.Result.flatMap(_result => {
// if TypeContracts.checkModifiers(contracts, aValue) {
// Ok(true)
// } else {
// T.TypeMismatch(anIType, aValue)->Error
// }
// })
// }
// switch anIType {
// | ItTypeIdentifier(name) => caseTypeIdentifier(name, aValue)
// | ItModifiedType({modifiedType, contracts}) =>
// caseModifiedType(anIType, modifiedType, contracts, aValue) //{modifiedType: iType, contracts: Belt.Map.String.t<Reducer_Value.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 isTypeOf = (
// typeExpressionSourceCode: string,
// aValue: Reducer_Value.t,
// reducerFn: Reducer_T.reducerFn,
// ): result<Reducer_Value.t, ErrorValue.t> => {
// 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->Reducer_Value.toString),
// )
// }
// | Error(error) => Error(error) // Directly propagating - err => err - causes type mismatch
// }
// }
// let checkITypeArguments = (anIType: T.iType, args: array<Reducer_Value.t>): result<
// bool,
// T.typeErrorValue,
// > => {
// switch anIType {
// | T.ItTypeFunction({inputs}) => isITypeOf(T.ItTypeTuple({elements: inputs}), args->IEvArray)
// | _ => T.TypeMismatch(anIType, args->IEvArray)->Error
// }
// }
// let checkITypeArgumentsBool = (anIType: T.iType, args: array<Reducer_Value.t>): bool => {
// switch checkITypeArguments(anIType, args) {
// | Ok(_) => true
// | _ => false
// }
// }
// let checkArguments = (
// typeExpressionSourceCode: string,
// args: array<Reducer_Value.t>,
// reducerFn: ReducerT.reducerFn,
// ): result<Reducer_Value.t, ErrorValue.t> => {
// 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->Reducer_Value.toString),
// )
// }
// | Error(error) => Error(error) // Directly propagating - err => err - causes type mismatch
// }
// }

View File

@ -21,8 +21,6 @@ let rec toString = (aValue: T.value) =>
| IEvRecord(aMap) => aMap->toStringRecord
| IEvString(aString) => toStringString(aString)
| IEvTimeDuration(t) => toStringTimeDuration(t)
| IEvType(aMap) => toStringType(aMap)
| IEvTypeIdentifier(id) => toStringTypeIdentifier(id)
| IEvVoid => toStringVoid
}
and toStringArray = anArray => {
@ -43,8 +41,6 @@ and toStringRecord = aMap => aMap->toStringMap
and toStringString = aString => `'${aString}'`
and toStringSymbol = aString => `:${aString}`
and toStringTimeDuration = t => DateTime.Duration.toString(t)
and toStringType = aMap => aMap->toStringMap
and toStringTypeIdentifier = id => `#${id}`
and toStringVoid = `()`
and toStringMap = aMap => {
@ -68,8 +64,6 @@ let toStringWithType = (aValue: T.value) =>
| IEvRecord(_) => `Record::${toString(aValue)}`
| IEvString(_) => `String::${toString(aValue)}`
| IEvTimeDuration(_) => `Date::${toString(aValue)}`
| IEvType(_) => `Type::${toString(aValue)}`
| IEvTypeIdentifier(_) => `TypeIdentifier::${toString(aValue)}`
| IEvVoid => `Void`
}
@ -114,8 +108,6 @@ type internalExpressionValueType =
| EvtRecord
| EvtString
| EvtTimeDuration
| EvtType
| EvtTypeIdentifier
| EvtVoid
type functionCallSignature = CallSignature(string, array<internalExpressionValueType>)
@ -134,8 +126,6 @@ let valueToValueType = (value: T.value) =>
| IEvRecord(_) => EvtRecord
| IEvString(_) => EvtString
| IEvTimeDuration(_) => EvtTimeDuration
| IEvType(_) => EvtType
| IEvTypeIdentifier(_) => EvtTypeIdentifier
| IEvVoid => EvtVoid
}
@ -148,7 +138,6 @@ let valueTypeToString = (valueType: internalExpressionValueType): string =>
switch valueType {
| EvtArray => `Array`
| EvtBool => `Bool`
// | EvtCall => `Call`
| EvtDate => `Date`
| EvtDeclaration => `Declaration`
| EvtDistribution => `Distribution`
@ -156,10 +145,7 @@ let valueTypeToString = (valueType: internalExpressionValueType): string =>
| EvtNumber => `Number`
| EvtRecord => `Record`
| EvtString => `String`
// | EvtSymbol => `Symbol`
| EvtTimeDuration => `Duration`
| EvtType => `Type`
| EvtTypeIdentifier => `TypeIdentifier`
| EvtVoid => `Void`
}