(: normalize-histogram ((Vectorof Real) -> (Vectorof Real)))
(define (normalize-histogram hist)
(let: ((sum (for/sum: : Real ([value : Real (in-vector hist)])
value)))
(for/vector: : (Vectorof Real) ([value : Real (in-vector hist)])
(/ value sum))))I should be able to say ((Vectorof Natural) -> (Vectorof Rational)) because the sum of natural is naturals the sum quotient of a natural and a natural is a (Positive) Rational.
I want to be able to know which branch of the case-> I'm in so that I can supply appropriate type annotations to the for macros.
For example, when normalizing a vector of numeric values, the output type should be the quotient closure of the input type. For example, a normalized vector of Naturals will be a vector of Rationals.
The heart of the issue is that the for macros require some annotation but that
annotation depends on the branch of the case->, which I cannot refer to.
If you have a workaround until something is pushed to TR mainline, I'd love to hear about it!
(: normalize-histogram (case-> ((Vectorof Real) -> (Vectorof Real))
((Vectorof Natural) -> (Vectorof Rational)))
(define (normalize-histogram hist)
(let: ((sum (for/sum: : ??? ([value : ??? (in-vector hist)])
value)))
(for/vector: : (Vectorof ???) ([value : ??? (in-vector hist)])
(/ value sum))))I should be able to say ((Vectorof Natural) -> (Vectorof Rational)) because the sum of natural is naturals the sum quotient of a natural and a natural is a (Positive) Rational.