Added Declaration toString

This commit is contained in:
Ozzie Gooen 2022-05-27 07:58:43 -04:00
parent 529a8a6763
commit 20f901e3f8
3 changed files with 22 additions and 7 deletions

View File

@ -11,7 +11,6 @@ type rec frType =
| FRTypeLambda
| FRTypeRecord(frTypeRecord)
| FRTypeArray(frType)
| FRTypeOption(frType)
| FRTypeString
| FRTypeVariant(array<string>)
and frTypeRecord = array<frTypeRecordParam>
@ -24,7 +23,6 @@ and frTypeRecordParam = (string, frType)
type rec frValue =
| FRValueNumber(float)
| FRValueDist(DistributionTypes.genericDist)
| FRValueOption(option<frValue>)
| FRValueArray(array<frValue>)
| FRValueDistOrNumber(frValueDistOrNumber)
| FRValueRecord(frValueRecord)
@ -60,7 +58,6 @@ module FRType = {
`record({${r->E.A2.fmap(input)->E.A2.joinWith(", ")}})`
}
| FRTypeArray(r) => `record(${toString(r)})`
| FRTypeOption(v) => `option(${toString(v)})`
| FRTypeLambda => `lambda`
| FRTypeString => `string`
| FRTypeVariant(_) => "variant"
@ -75,7 +72,6 @@ module FRType = {
| (FRTypeDistOrNumber, EvDistribution(f)) => Some(FRValueDistOrNumber(FRValueDist(f)))
| (FRTypeNumeric, EvNumber(f)) => Some(FRValueNumber(f))
| (FRTypeNumeric, EvDistribution(Symbolic(#Float(f)))) => Some(FRValueNumber(f))
| (FRTypeOption(v), _) => Some(FRValueOption(matchWithExpressionValue(v, r)))
| (FRTypeLambda, EvLambda(f)) => Some(FRValueLambda(f))
| (FRTypeArray(intendedType), EvArray(elements)) => {
let el = elements->E.A2.fmap(matchWithExpressionValue(intendedType))
@ -101,7 +97,6 @@ module FRType = {
| FRValueDistOrNumber(FRValueNumber(n)) => EvNumber(n)
| FRValueDistOrNumber(FRValueDist(n)) => EvDistribution(n)
| FRValueDist(dist) => EvDistribution(dist)
| FRValueOption(Some(r)) => matchReverse(r)
| FRValueArray(elements) => EvArray(elements->E.A2.fmap(matchReverse))
| FRValueRecord(frValueRecord) => {
let record =
@ -113,7 +108,6 @@ module FRType = {
| FRValueVariant(string) => EvString(string)
}
// | FRValueOption(None) => break
let matchWithExpressionValueArray = (inputs: array<t>, args: array<expressionValue>): option<
array<frValue>,
> => {

View File

@ -57,7 +57,7 @@ let rec toString = aValue =>
| EvDistribution(dist) => GenericDist.toString(dist)
| EvDate(date) => DateTime.Date.toString(date)
| EvTimeDuration(t) => DateTime.Duration.toString(t)
| EvDeclaration(t) => "Declaration"
| EvDeclaration(d) => Declaration.toString(d, r => toString(EvLambda(r)))
}
and toStringRecord = aRecord => {
let pairs =
@ -128,6 +128,7 @@ type expressionValueType =
| EvtSymbol
| EvtDate
| EvtTimeDuration
| EvtDeclaration
type functionCallSignature = CallSignature(string, array<expressionValueType>)
type functionDefinitionSignature =
@ -147,6 +148,7 @@ let valueToValueType = value =>
| EvSymbol(_) => EvtSymbol
| EvDate(_) => EvtDate
| EvTimeDuration(_) => EvtTimeDuration
| EvDeclaration(_) => EvtDeclaration
}
let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => {
@ -168,6 +170,7 @@ let valueTypeToString = (valueType: expressionValueType): string =>
| EvtSymbol => `Symbol`
| EvtDate => `Date`
| EvtTimeDuration => `Duration`
| EvtDeclaration => `Declaration`
}
let functionCallSignatureToString = (functionCallSignature: functionCallSignature): string => {

View File

@ -19,6 +19,24 @@ module ContinuousTimeArg = {
}
}
module Arg = {
let toString = (arg: arg) => {
switch arg {
| Float({min, max}) =>
`Float({min: ${E.Float.with2DigitsPrecision(min)}, max: ${E.Float.with2DigitsPrecision(
max,
)}})`
| Date({min, max}) =>
`Date({min: ${DateTime.Date.toString(min)}, max: ${DateTime.Date.toString(max)}})`
}
}
}
let make = (fn: 'a, args: array<arg>): declaration<'a> => {
{fn: fn, args: args}
}
let toString = (r: declaration<'a>, fnToString): string => {
let args = r.args->E.A2.fmap(Arg.toString) |> E.A.joinWith(", ")
return`fn: ${fnToString(r.fn)}, args: [${args}]`
}