diff --git a/src/core/Type.js b/src/core/Type.js index 868da71..088b9e7 100644 --- a/src/core/Type.js +++ b/src/core/Type.js @@ -1,4 +1,6 @@ import ArrayKeyedMap from 'array-keyed-map' +import {match} from './helpers.js' +import {Passthru} from './TypePatterns.js' // Generic types are callable, so we have no choice but to extend Function export class Type extends Function { @@ -86,7 +88,7 @@ export const whichType = typs => Returns(TypeOfTypes, item => { throw new TypeError(errorMsg) }) -export const typeOf = math => whichType(math.types) +export const typeOf = match(Passthru, math => whichType(math.types)) // bootstrapping order matters, but order of exports in a module isn't // simply the order that the items are listed in the module. So we make diff --git a/src/core/TypeDispatcher.js b/src/core/TypeDispatcher.js index 903cb5b..202afe1 100644 --- a/src/core/TypeDispatcher.js +++ b/src/core/TypeDispatcher.js @@ -103,6 +103,10 @@ export class TypeDispatcher { // right here: if (val instanceof Matcher) val = new Implementations(val) if (Array.isArray(val)) val = new Implementations(val) + if (isPlainFunction(val)) { + throw new RangeError( + `function value for ${key} must be merged within a 'match' call`) + } if (!(val instanceof Implementations)) { val = new Implementations(match(Passthru, val)) } diff --git a/src/generic/relational.js b/src/generic/relational.js index 9022777..810c06a 100644 --- a/src/generic/relational.js +++ b/src/generic/relational.js @@ -1,7 +1,7 @@ import {ReturnsAs} from './helpers.js' import {match} from '#core/helpers.js' import {Returns} from '#core/Type.js' -import {Any, matched} from '#core/TypePatterns.js' +import {Any, Passthru, matched} from '#core/TypePatterns.js' import {boolnum} from '#number/helpers.js' export const equal = match([Any, Any], (math, [T, U]) => { @@ -76,10 +76,10 @@ export const sign = match(Any, (math, T) => { return ReturnsAs(comp, t => comp(t, zero)) }) -export const unequal = (math, types) => { +export const unequal = match(Passthru, (math, types) => { const eq = math.equal.resolve(types) return ReturnsAs(eq, (...args) => !eq(...args)) -} +}) export const larger = match([Any, Any], (math, [T, U]) => { const eq = math.equal.resolve([T, U]) diff --git a/src/generic/utils.js b/src/generic/utils.js index 8fc8a82..d4c8f87 100644 --- a/src/generic/utils.js +++ b/src/generic/utils.js @@ -1,13 +1,13 @@ import {ReturnsAs} from './helpers.js' -import {ResolutionError} from '#core/helpers.js' +import {ResolutionError, match} from '#core/helpers.js' import {Returns} from '#core/Type.js' -import {Any} from "#core/TypePatterns.js" +import {Passthru} from "#core/TypePatterns.js" -export const isZero = (math, [T]) => { +export const isZero = match(Passthru, (math, [T]) => { if (!T) { // called with no arguments throw new ResolutionError('isZero() requires one argument') } const z = math.zero(T) const eq = math.equal.resolve([T, T]) return ReturnsAs(eq, x => eq(z, x)) -} +})