demolish external expression value

This commit is contained in:
Umur Ozkul 2022-08-19 17:30:29 +02:00
parent f0ba68f64a
commit af4070a34f
18 changed files with 11 additions and 137 deletions

View File

@ -1,37 +0,0 @@
open ForTS_Types_
@module("ForTS_InternalValue_tag") @scope("InternalValueTag")
external ivtVoid_: int = "IvtVoid"
@module("ForTS_InternalValue_tag") @scope("InternalValueTag")
external ivtString_: int = "IvtString"
@module("ForTS_InternalValue_tag") @scope("InternalValueTag")
external ivtRecordLike_: int = "IvtRecordLike"
@genType
let getTag = (variant: internalValue) =>
switch variant {
| IvVoid(_) => ivtVoid_
| IvString(_) => ivtString_
| IvRecordLike(_) => ivtRecordLike_
}
@genType
let getVoid = (variant: internalValue): option<internalVoid> =>
switch variant {
| IvVoid(v) => Some(v)
| _ => None
}
@genType
let getString = (variant: internalValue): option<string> =>
switch variant {
| IvString(s) => Some(s)
| _ => None
}
@genType
let getRecordLike = (variant: internalValue): option<recordLike> =>
switch variant {
| IvRecordLike(r) => Some(r)
| _ => None
}

View File

@ -1,8 +0,0 @@
open ForTS_Types_
@genType
let toString = (v: recordLike): string =>
MyInterface_InternalValue_RecordLike.toString(v, MyInterface_InternalValue.toString)
@genType
let toArray = (v: recordLike): array<(string, internalValue)> =>
MyInterface_InternalValue_RecordLike.toArray(v)

View File

@ -1 +0,0 @@
@genType let toString = (value: string): string => value

View File

@ -1,3 +0,0 @@
open ForTS_Types_
@genType let toString = (_value: internalVoid): string => MyInterface_InternalValue_Void.toString

View File

@ -1,7 +0,0 @@
enum InternalValueTag {
IvtVoid,
IvtString,
IvtRecordLike
}

View File

@ -1,5 +0,0 @@
open ForTS_Types_
@genType
let getResult = (_p: myProject): option<result_<internalValue, errorValue>> =>
My_ErrorValue.EError->Error->Some

View File

@ -1,18 +0,0 @@
open ForTS_Types_
@genType let isError = (r: result_<'a, 'e>): bool => Belt.Result.isError(r)
@genType let isOk = (r: result_<'a, 'e>): bool => Belt.Result.isOk(r)
@genType
let getError = (r: result_<'a, 'e>): option<'e> =>
switch r {
| Ok(_) => None
| Error(e) => Some(e)
}
@genType
let getValue = (r: result_<'a, 'e>): option<'a> =>
switch r {
| Ok(v) => Some(v)
| Error(_) => None
}

View File

@ -1,12 +0,0 @@
/*
Group all opaque types together for TS.
All other modules for TS should use this module
*/
@genType.opaque type internalValue = MyInterface_InternalValue_T.t
@genType.opaque type recordLike = MyInterface_InternalValue_RecordLike.t
@genType.opaque type internalVoid = int
@genType.opaque type errorValue = My_ErrorValue.t
@genType.opaque type result_<'a, 'e> = result<'a, 'e>
@genType.opaque type myProject = {name: string}
//There is no need to map option<> as it becomes nullable

View File

@ -1,10 +0,0 @@
type errorValue = EError | EErrorString(string) | EErrorNumber(float)
type t = errorValue
let toString = (e: errorValue): string => {
switch e {
| EError => "Error"
| EErrorString(s) => s
| EErrorNumber(f) => Js.Float.toString(f)
}
}

View File

@ -1,9 +0,0 @@
open MyInterface_InternalValue_T
let rec toString = (v: internalValue): string => {
switch v {
| IvString(s) => MyInterface_InternalValue_String.toString(s)
| IvRecordLike(m) => MyInterface_InternalValue_RecordLike.toString(m, toString)
| IvVoid(_v) => MyInterface_InternalValue_Void.toString
}
}

View File

@ -1,12 +0,0 @@
type t = MyInterface_InternalValue_T.recordLike
let toString = (value: t, recToString) => {
let contents =
Belt.Map.String.mapWithKey(value, (key, value) => {
`${key}: ${recToString(value)}`
})
->Belt.Map.String.toArray
->Js.Array2.joinWith(", ")
`{${contents}}`
}
let toArray = (value: t) => Belt.Map.String.toArray(value)

View File

@ -1,7 +0,0 @@
type rec internalValue =
| IvString(string)
| IvRecordLike(recordLike)
| IvVoid(int)
and recordLike = Belt.Map.String.t<internalValue>
type t = internalValue

View File

@ -1 +0,0 @@
To be trashed. Experimental code

View File

@ -1 +1,6 @@
open ForTS__Types
/*
Global variables, functions, helpers, etc.
*/
@genType
let defaultEnvironment: environment = DistributionOperation.defaultEnv

View File

@ -1,10 +1,10 @@
@genType.opaque type result_<'a, 'e> = result<'a, 'e>
/*
The reason this is not ExpressionValue is that ExpressionValue is becoming a parametric type
to allow expressions for different domains.
So we rename it right away not cause a compatibility problem
*/
@genType.opaque type result_<'a, 'e> = result<'a, 'e>
@genType.opaque type squiggleValue = ReducerInterface_InternalExpressionValue.t
@genType.opaque type squiggleValue_Array = ReducerInterface_InternalExpressionValue.squiggleArray
@genType.opaque
@ -17,7 +17,8 @@ type squiggleValue_Declaration = ReducerInterface_InternalExpressionValue.lambda
@genType.opaque type reducerProject = ReducerProject_T.t
// From now on one should introduce any new types as opaque types
// From now on one should introduce any new types as opaque types.
// Exception: The intended type is really a JavaScript type or record. Not by coincidence
// Already existing open types we cannot dive in now
@genType type environment = GenericDist.env
@genType type squiggleValue_Distribution = DistributionTypes.genericDist