Allow primitives in Trait declarations
Closed this issue · 0 comments
mlhaufe commented
Current approach on fibonacci and similar function require an undefined
dataDecl and the use of [all]
:
const fib = Trait(undefined, {
[all]: (n) => n == 0 ? 0 :
n == 1 ? 1 :
fib(n-1) + fib(n-2)
})
Allowing primitives and resolving #34 would enable the following:
const fib = Trait(Number, {
0: () => 0,
1: () => 1,
_: (n) => fib(n-1) + fib(n-2)
})
Primitives to support:
Trait(Number, {
1: () => {},
[Infinity]: () => {},
[Number.EPSILON]: () => {},
[Number.MAX_SAFE_INTEGER]: () => {},
[Number.MAX_VALUE]: () => {},
[Number.MIN_VALUE]: () => {},
[Number.NaN]: () => {},
[NaN]: () => {},
[Number.POSITIVE_INFINITY]: () => {},
[Number.NEGATIVE_INFINITY]: () => {},
})
Trait(Boolean, {
false: () => {},
true: () => {}
})
Trait(BigInt, {
[2n]: () => {}
})
Trait(String, {
'arbitrary string': () => {}
})