Update Item Specifications
parent
f4ae307c5e
commit
587be22dd5
1 changed files with 14 additions and 1 deletions
|
@ -18,7 +18,20 @@ export const square = (math, [T]) => {
|
|||
Note that we should not write
|
||||
```
|
||||
export const square = (math, [T]) => {
|
||||
return a => math.multiply(a, a)
|
||||
return a => math.multiply(a, a)
|
||||
}
|
||||
```
|
||||
That's because in order to work as a dependency, the dependent items must be extracted within the body of the function that provides the final behavior/value for the item, not within that behavior.
|
||||
|
||||
There's another wrinkle; we want to record the return type of all of the methods, both for writing TypeScript type definition files and for making it easier to select the best implementations for other methods. So we will really need to write something like:
|
||||
```
|
||||
export const square = (math, [T]) => {
|
||||
const mul = math.get('multiply', [T, T])
|
||||
return Returns(mul.returns, a => mul(a, a))
|
||||
}
|
||||
```
|
||||
|
||||
This seems a trifle "heavy" but I'm not seeing clear ways at the moment to streamline it.
|
||||
|
||||
Another point here is that this implementation of square works for all types, so there is not any type matching going on in the definition. So let's take a look at what we would have to do for the `multiply` implementation on two numbers -- a plain function with no dependencies. Something like
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue