feat: Add return typing strategies and implement sqrt with them (#26)
All checks were successful
/ test (push) Successful in 17s
All checks were successful
/ test (push) Successful in 17s
Resolves #25 Reviewed-on: #26 Co-authored-by: Glen Whitney <glen@studioinfinity.org> Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
parent
aad62df8ac
commit
0765ba7202
35 changed files with 1125 additions and 152 deletions
|
|
@ -1,8 +1,15 @@
|
|||
import {Returns} from '#core/Type.js'
|
||||
import {ReturnsAs} from './helpers.js'
|
||||
|
||||
import {Returns, ReturnTyping} from '#core/Type.js'
|
||||
import {match, Any} from '#core/TypePatterns.js'
|
||||
|
||||
export const conj = match(Any, (_math, T) => Returns(T, a => a))
|
||||
export const square = match(Any, (math, T) => {
|
||||
const mult = math.multiply.resolve([T, T])
|
||||
return Returns(mult.returns, a => mult(a, a))
|
||||
export const abs = match(Any, (math, T) => {
|
||||
const absq = math.absquare.resolve(T)
|
||||
const sqrt = math.sqrt.resolve(absq.returns, ReturnTyping.conservative)
|
||||
return ReturnsAs(sqrt, t => sqrt(absq(t)))
|
||||
})
|
||||
export const conj = match(Any, (_math, T) => Returns(T, t => t))
|
||||
export const square = match(Any, (math, T, strategy) => {
|
||||
const mult = math.multiply.resolve([T, T], strategy)
|
||||
return Returns(mult.returns, t => mult(t, t))
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue