From 545b4f6c33a3b623e4a05d2ab256b60e15d8a6b9 Mon Sep 17 00:00:00 2001 From: "Amy J. Ko" Date: Mon, 18 Sep 2023 18:09:35 -0700 Subject: [PATCH] Removed concept of wildcard. --- src/basis/NumberBasis.ts | 18 +++++++++--------- src/input/Random.ts | 6 +----- src/nodes/Is.test.ts | 2 +- src/nodes/NumberType.ts | 12 +++--------- src/nodes/UnionType.test.ts | 2 +- src/nodes/Unit.ts | 20 +++----------------- 6 files changed, 18 insertions(+), 42 deletions(-) diff --git a/src/basis/NumberBasis.ts b/src/basis/NumberBasis.ts index eeebb0e0b..181b77148 100644 --- a/src/basis/NumberBasis.ts +++ b/src/basis/NumberBasis.ts @@ -263,7 +263,7 @@ export default function bootstrapNumber(locales: Locale[]) { createBinaryOp( (locale) => locale.basis.Number.function.multiply, // The operand's type can be any unitless measurement - NumberType.wildcard(), + NumberType.make(), // The output's type is is the unit's product NumberType.make((left, right) => right ? left.product(right) : left @@ -273,7 +273,7 @@ export default function bootstrapNumber(locales: Locale[]) { ), createBinaryOp( (locale) => locale.basis.Number.function.divide, - NumberType.wildcard(), + NumberType.make(), NumberType.make((left, right) => right ? left.quotient(right) : left ), @@ -282,7 +282,7 @@ export default function bootstrapNumber(locales: Locale[]) { ), createBinaryOp( (locale) => locale.basis.Number.function.remainder, - NumberType.wildcard(), + NumberType.make(), NumberType.make((left) => left), (requestor, left, right) => left.remainder(requestor, right), @@ -290,27 +290,27 @@ export default function bootstrapNumber(locales: Locale[]) { ), createUnaryOp( (locale) => locale.basis.Number.function.roundDown, - NumberType.wildcard(), + NumberType.make(), (requestor, left) => left.roundDown(requestor) ), createUnaryOp( (locale) => locale.basis.Number.function.roundUp, - NumberType.wildcard(), + NumberType.make(), (requestor, left) => left.roundUp(requestor) ), createUnaryOp( (locale) => locale.basis.Number.function.positive, - NumberType.wildcard(), + NumberType.make(), (requestor, left) => left.absolute(requestor) ), createUnaryOp( (locale) => locale.basis.Number.function.round, - NumberType.wildcard(), + NumberType.make(), (requestor, left) => left.round(requestor) ), createBinaryOp( (locale) => locale.basis.Number.function.power, - NumberType.wildcard(), + NumberType.make(), NumberType.make((left, right, constant) => { right; return constant === undefined @@ -322,7 +322,7 @@ export default function bootstrapNumber(locales: Locale[]) { ), createBinaryOp( (locale) => locale.basis.Number.function.root, - NumberType.wildcard(), + NumberType.make(), NumberType.make((left, right, constant) => { right; return constant === undefined diff --git a/src/input/Random.ts b/src/input/Random.ts index eea15420f..8115d0cb1 100644 --- a/src/input/Random.ts +++ b/src/input/Random.ts @@ -7,7 +7,6 @@ import type Locale from '../locale/Locale'; import { createBasisFunction } from '../basis/Basis'; import type Evaluation from '../runtime/Evaluation'; import type Expression from '../nodes/Expression'; -import Unit from '../nodes/Unit'; import NoneValue from '../values/NoneValue'; import TypeVariables from '../nodes/TypeVariables'; import TypeVariable from '../nodes/TypeVariable'; @@ -69,10 +68,7 @@ function toPrecisionRange( export function createRandomFunction(locales: Locale[]) { /** The type variable can be any number type, but nothing else */ - const NumberTypeVariable = TypeVariable.make( - ['Number'], - NumberType.make(Unit.Wildcard) - ); + const NumberTypeVariable = TypeVariable.make(['Number'], NumberType.make()); return createBasisFunction( locales, diff --git a/src/nodes/Is.test.ts b/src/nodes/Is.test.ts index 2b3999296..ee3733230 100644 --- a/src/nodes/Is.test.ts +++ b/src/nodes/Is.test.ts @@ -3,7 +3,7 @@ import evaluateCode from '../runtime/evaluate'; test.each([ ['1•#', '⊤'], - ['1s•#', '⊥'], + ['1s•#', '⊤'], ['1s•#s', '⊤'], ['1s•#m', '⊥'], ["'hi'•#", '⊥'], diff --git a/src/nodes/NumberType.ts b/src/nodes/NumberType.ts index f75bef229..25a3bf6bb 100644 --- a/src/nodes/NumberType.ts +++ b/src/nodes/NumberType.ts @@ -58,15 +58,9 @@ export default class NumberType extends BasisType { return [NumberType.make()]; } - static wildcard() { - return NumberType.make(Unit.Wildcard); - } - generalize() { - // Remove the wildcard if it is one. - return this.unit instanceof Unit && this.unit.isWildcard() - ? NumberType.make() - : NumberType.make(this.unit); + // Remove the specific number, if there is one, but preserve the unit. + return NumberType.make(this.unit); } getGrammar(): Grammar { @@ -130,7 +124,7 @@ export default class NumberType extends BasisType { // If the units aren't compatible, then the the types aren't compatible. if ( - !(this.unit instanceof Function || this.unit.isWildcard()) && + !(this.unit instanceof Function || this.unit.isUnitless()) && !thisUnit.accepts(thatUnit) ) return false; diff --git a/src/nodes/UnionType.test.ts b/src/nodes/UnionType.test.ts index da0e40ac4..afa112117 100644 --- a/src/nodes/UnionType.test.ts +++ b/src/nodes/UnionType.test.ts @@ -10,7 +10,7 @@ test.each([ ["'hi'/en|'hello'/en", "''/en"], ["'hi'/en|'hi'/fr", "''/en|''/fr"], ['1|2|3', '#'], - ['1m|2|3', '#m|#'], + ['1m|2|3', '#'], ['1m|2m|3m', '#m'], ['[1|2|3]', '[#]'], ['{1}', '{#}'], diff --git a/src/nodes/Unit.ts b/src/nodes/Unit.ts index aa50956d9..dfcab12c7 100644 --- a/src/nodes/Unit.ts +++ b/src/nodes/Unit.ts @@ -1,8 +1,4 @@ -import { - QUESTION_SYMBOL, - EXPONENT_SYMBOL, - LANGUAGE_SYMBOL, -} from '@parser/Symbols'; +import { EXPONENT_SYMBOL, LANGUAGE_SYMBOL } from '@parser/Symbols'; import { PRODUCT_SYMBOL } from '@parser/Symbols'; import Dimension from './Dimension'; import Token from './Token'; @@ -153,11 +149,6 @@ export default class Unit extends Type { } static Empty = new Unit(); - static Wildcard = (() => { - const exp = new Map(); - exp.set(QUESTION_SYMBOL, 1); - return new Unit(exp); - })(); getGrammar(): Grammar { return [ @@ -218,9 +209,6 @@ export default class Unit extends Type { return newUnit; } - isWildcard() { - return this.exponents.get('?') === 1; - } isUnitless() { return this.exponents.size === 0; } @@ -278,10 +266,8 @@ export default class Unit extends Type { // And... // The units are equal (this.isEqualTo(unit) || - // Or this is a wildcard - this.isWildcard() || - // Or this is unitless and the unit is a wildcard - (this.isUnitless() && unit.isWildcard())) + // Or this is unitless + this.isUnitless()) ); }