feat: Add and illustrate multiple ways of specifying implementations (#19)
Resolves #9. Co-authored-by: Glen Whitney <glen@studioinfinity.org> Reviewed-on: #19
This commit is contained in:
parent
4fdafc751e
commit
d72c443616
9 changed files with 81 additions and 22 deletions
|
@ -1,10 +1,13 @@
|
|||
export {Types} from './Types/Complex.mjs'
|
||||
|
||||
export const add = {
|
||||
'...Complex': [['self'], ref => addends => {
|
||||
if (addends.length === 0) return {re:0, im:0}
|
||||
const seed = addends.shift()
|
||||
return addends.reduce((w,z) =>
|
||||
({re: ref.self(w.re, z.re), im: ref.self(w.im, z.im)}), seed)
|
||||
}]
|
||||
'...Complex': {
|
||||
uses: ['self'],
|
||||
does: ref => addends => {
|
||||
if (addends.length === 0) return {re:0, im:0}
|
||||
const seed = addends.shift()
|
||||
return addends.reduce((w,z) =>
|
||||
({re: ref.self(w.re, z.re), im: ref.self(w.im, z.im)}), seed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ export const complex = {
|
|||
* have a numeric/scalar type, e.g. by implementing subtypes in
|
||||
* typed-function
|
||||
*/
|
||||
'any, any': [[], (x, y) => ({re: x, im: y})],
|
||||
'any, any': {does: (x, y) => ({re: x, im: y})},
|
||||
/* Take advantage of conversions in typed-function */
|
||||
Complex: [[], z => z]
|
||||
Complex: {does: z => z}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
export {Types} from './Types/Complex.mjs'
|
||||
|
||||
export const negate = {
|
||||
Complex: [['self'], ref => z => {
|
||||
return {re: ref.self(z.re), im: ref.self(z.im)}
|
||||
}]
|
||||
Complex: {
|
||||
uses: ['self'],
|
||||
does: ref => z => {
|
||||
return {re: ref.self(z.re), im: ref.self(z.im)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue