38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
import R_ from '../core/returns.mjs'
|
|
export * from './Types/number.mjs'
|
|
|
|
export const negate = {
|
|
NumInt: () => R_('NumInt', n => -n),
|
|
number: () => R_('number', n => -n)
|
|
}
|
|
/* Can we find a mechanism to avoid reiterating the definition
|
|
for each number (sub)type? Maybe something like:
|
|
|
|
export const negate = {'T:number': ({T}) => R_(T, n => -n)}
|
|
|
|
where 'T:number' is a new notation that means "T is a (non-strict) subtype
|
|
of number". That doesn't look too bad, but if we went down that route, we
|
|
might also need to make sure that if we ever implemented a PositiveNumber
|
|
type and a NegativeNumber type then we could say
|
|
|
|
export const negate = {
|
|
PositiveNumber: () => R_('NegativeNumber', n => -n),
|
|
NegativeNumber: () => R_('PositiveNumber', n => -n),
|
|
'T:number': ({T}) => R_(T, n => -n)
|
|
}
|
|
|
|
|
|
This just gets worse if there are also PosNumInt and NegNumInt types;
|
|
maybe Positive<T>, Negative<T>, and Zero<T> are template types, so that
|
|
we could say:
|
|
|
|
export const negate = {
|
|
'Positive<T:number>': ({'Negative<T>': negT}) => R_(negT, n => -n),
|
|
'Negative<T:number>': ({'Positive<T>': posT}) => R_(posT, n => -n),
|
|
T:number: ({T}) => R_(T, n => -n)
|
|
}
|
|
|
|
But all of that is pretty speculative, for now let's just go with writing
|
|
out the different types.
|
|
*/
|