feat: Template types for Pocomath

Tuple<T> and a couple of functions on it are now working according to
  the target spec. As desired, no instantiations of a template type
  are made until some function that takes an instantiation is called.
This commit is contained in:
Glen Whitney 2022-08-04 08:23:14 -07:00
parent a743337134
commit b0fb004224
7 changed files with 190 additions and 44 deletions

View file

@ -8,13 +8,11 @@ Tuple.installType('Tuple', {
})
// Now the template type that is the primary use of this
Tuple.installType('Tuple<T>', {
// For now we will assume that any 'Type<T>' refines 'Type', so this is
// We are assuming that any 'Type<T>' refines 'Type', so this is
// not necessary:
// refines: 'Tuple',
// But we need there to be a way to determine the type of a tuple:
infer: ({typeOf, joinTypes}) => t => {
return joinTypes(t.elts.map(typeOf))
},
infer: ({typeOf, joinTypes}) => t => joinTypes(t.elts.map(typeOf)),
// For the test, we can assume that t is already a base tuple,
// and we get the test for T as an input and we have to return
// the test for Tuple<T>

View file

@ -1,6 +1,8 @@
export {Tuple} from './Types/Tuple.mjs'
export const isZero = {
'Tuple<T>': ({'self(T)': me}) => t => t.elts.every(isZero)
'Tuple<T>': ({'self(T)': me}) => t => t.elts.every(e => me(e))
// Note we can't just say `every(me)` above since every invokes its
// callback with more arguments, which then violates typed-function's
// signature for `me`
}

View file

@ -3,4 +3,4 @@ export {Tuple} from './Types/Tuple.mjs'
/* The purpose of the template argument is to ensure that all of the args
* are convertible to the same type.
*/
export const tuple = {'...any': () => args => ({elts: args})}
export const tuple = {'...T': () => args => ({elts: args})}