non-opaque results
This commit is contained in:
parent
7dd9a5bb77
commit
1f22d1f837
|
@ -1,4 +1,3 @@
|
||||||
type result<'a, 'e> = ForTS_Result.result<'a, 'e> // Use opaque result type
|
|
||||||
type functionCallInfo = DistributionTypes.DistributionOperation.genericFunctionCallInfo
|
type functionCallInfo = DistributionTypes.DistributionOperation.genericFunctionCallInfo
|
||||||
type genericDist = DistributionTypes.genericDist
|
type genericDist = DistributionTypes.genericDist
|
||||||
type error = DistributionTypes.error
|
type error = DistributionTypes.error
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
type result<'a, 'e> = ForTS_Result.result<'a, 'e> // Use opaque result type
|
|
||||||
@genType
|
@genType
|
||||||
let defaultEnv: GenericDist.env
|
let defaultEnv: GenericDist.env
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
//TODO: multimodal, add interface, test somehow, track performance, refactor sampleSet, refactor ASTEvaluator.res.
|
//TODO: multimodal, add interface, test somehow, track performance, refactor sampleSet, refactor ASTEvaluator.res.
|
||||||
type result<'a, 'e> = ForTS_Result.result<'a, 'e> // Use opaque result type
|
|
||||||
|
|
||||||
type t = DistributionTypes.genericDist
|
type t = DistributionTypes.genericDist
|
||||||
type error = DistributionTypes.error
|
type error = DistributionTypes.error
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
type result<'a, 'e> = ForTS_Result.result<'a, 'e> // Use opaque result type
|
|
||||||
|
|
||||||
type t = DistributionTypes.genericDist
|
type t = DistributionTypes.genericDist
|
||||||
type error = DistributionTypes.error
|
type error = DistributionTypes.error
|
||||||
type toPointSetFn = t => result<PointSetTypes.pointSetDist, error>
|
type toPointSetFn = t => result<PointSetTypes.pointSetDist, error>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
@genType type reducerProject = ReducerProject_T.t //re-export
|
@genType type reducerProject = ReducerProject_T.t //re-export
|
||||||
|
|
||||||
type result<'a, 'e> = ForTS_Result.result<'a, 'e> // Use opaque result type
|
|
||||||
type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use
|
type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use
|
||||||
|
|
||||||
type squiggleValue = ForTS_SquiggleValue.squiggleValue //use
|
type squiggleValue = ForTS_SquiggleValue.squiggleValue //use
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
@genType.opaque type result_<'a, 'e> = result<'a, 'e>
|
|
||||||
@genType type result<'a, 'e> = result_<'a, 'e> // alias and re-export
|
|
||||||
|
|
||||||
@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
|
|
||||||
}
|
|
||||||
|
|
||||||
@module("./ForTS_Result_tag") @scope("resultTag")
|
|
||||||
external rtOk_: int = "RtOk"
|
|
||||||
|
|
||||||
@module("./ForTS_Result_tag") @scope("resultTag")
|
|
||||||
external rtError_: int = "RtError"
|
|
||||||
|
|
||||||
@genType.import("./ForTS_Result_tag")
|
|
||||||
type resultTag
|
|
||||||
|
|
||||||
external castEnum: int => resultTag = "%identity"
|
|
||||||
|
|
||||||
@genType
|
|
||||||
let getTag = (r: result<'a, 'e>): resultTag =>
|
|
||||||
switch r {
|
|
||||||
| Ok(_) => rtOk_->castEnum
|
|
||||||
| Error(_) => rtError_->castEnum
|
|
||||||
}
|
|
||||||
|
|
||||||
@genType
|
|
||||||
let fmap = (r: result<'a, 'e>, f: 'a => 'b): result<'b, 'e> =>
|
|
||||||
switch r {
|
|
||||||
| Ok(v) => Ok(f(v))
|
|
||||||
| Error(e) => Error(e)
|
|
||||||
}
|
|
|
@ -1,4 +1,9 @@
|
||||||
export enum resultTag {
|
export type result<a, b> =
|
||||||
RtOk,
|
| {
|
||||||
RtError,
|
tag: "Ok";
|
||||||
|
value: a;
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
tag: "Error";
|
||||||
|
value: b;
|
||||||
|
};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
@genType type squiggleValue = ReducerInterface_InternalExpressionValue.t //re-export
|
@genType type squiggleValue = ReducerInterface_InternalExpressionValue.t //re-export
|
||||||
type result_<'a, 'e> = ForTS_Result.result_<'a, 'e> //use
|
|
||||||
type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use
|
type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use
|
||||||
|
|
||||||
@genType type squiggleValue_Array = ReducerInterface_InternalExpressionValue.squiggleArray //re-export recursive type
|
@genType type squiggleValue_Array = ReducerInterface_InternalExpressionValue.squiggleArray //re-export recursive type
|
||||||
|
@ -97,7 +96,7 @@ let toString = (variant: squiggleValue) =>
|
||||||
// This is a useful method for unit tests.
|
// This is a useful method for unit tests.
|
||||||
// Convert the result along with the error message to a string.
|
// Convert the result along with the error message to a string.
|
||||||
@genType
|
@genType
|
||||||
let toStringResult = (variantResult: result_<squiggleValue, reducerErrorValue>) =>
|
let toStringResult = (variantResult: result<squiggleValue, reducerErrorValue>) =>
|
||||||
ReducerInterface_InternalExpressionValue.toStringResult(variantResult)
|
ReducerInterface_InternalExpressionValue.toStringResult(variantResult)
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
@genType type result_<'a, 'e> = ForTS_Result.result_<'a, 'e> //re-export
|
|
||||||
@genType type result<'a, 'e> = ForTS_Result.result<'a, 'e> //re-export
|
|
||||||
@genType type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //re-export
|
@genType type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //re-export
|
||||||
@genType type syntaxErrorLocation = ForTS_Reducer_ErrorValue.syntaxErrorLocation //re-export
|
@genType type syntaxErrorLocation = ForTS_Reducer_ErrorValue.syntaxErrorLocation //re-export
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,12 @@ The below few seem to work fine. In the future there's definitely more work to d
|
||||||
@genType type genericDist = squiggleValue_Distribution //alternative
|
@genType type genericDist = squiggleValue_Distribution //alternative
|
||||||
@genType type sampleSetDist = sampleSetDistribution //alternative
|
@genType type sampleSetDist = sampleSetDistribution //alternative
|
||||||
@genType type symbolicDist = symbolicDistribution //alternative
|
@genType type symbolicDist = symbolicDistribution //alternative
|
||||||
@genType type resultDist = result_<distribution, distributionError> //alternative
|
@genType type resultDist = result<distribution, distributionError> //alternative
|
||||||
@genType type resultFloat = result_<float, distributionError> //alternative
|
@genType type resultFloat = result<float, distributionError> //alternative
|
||||||
@genType type resultString = result_<string, distributionError> //alternative
|
@genType type resultString = result<string, distributionError> //alternative
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
let makeSampleSetDist: array<float> => result_<
|
let makeSampleSetDist: array<float> => result<
|
||||||
sampleSetDist,
|
sampleSetDist,
|
||||||
SampleSetDist.sampleSetError,
|
SampleSetDist.sampleSetError,
|
||||||
> = SampleSetDist.make
|
> = SampleSetDist.make
|
||||||
|
@ -33,7 +33,7 @@ let toPointSet: (
|
||||||
~sampleCount: int,
|
~sampleCount: int,
|
||||||
~xSelection: DistributionTypes.DistributionOperation.pointsetXSelection=?,
|
~xSelection: DistributionTypes.DistributionOperation.pointsetXSelection=?,
|
||||||
unit,
|
unit,
|
||||||
) => result_<PointSetTypes.pointSetDist, distributionError> = GenericDist.toPointSet
|
) => result<PointSetTypes.pointSetDist, distributionError> = GenericDist.toPointSet
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
type mixedShape = PointSetTypes.mixedShape
|
type mixedShape = PointSetTypes.mixedShape
|
||||||
|
|
Loading…
Reference in New Issue
Block a user