No safety in numbers
Jon Cast
jcast@cate0-46.reshall.ou.edu
Thu, 21 Aug 2003 15:42:41 -0500
Konrad Hinsen <hinsen@cnrs-orleans.fr> wrote:
> I am trying to write a larger piece of code using only type
> constraints for all the numbers, not specific types, in order to be
> able to choose the precision as late as possible.
Good for you! (I say this in all seriousness.)
> This works rather well (something I can't say of many other
> languages), but one problem I keep running into is constants.
>
> Something I need frequently is, for example, the Boltzman constant,
> 0.0083144708636327096 in my unit system. I can certainly type
> 0.0083144708636327096 everywhere in the code and make things work,
> literals have the nice property of being overloaded. But for the sake
> of readibility, I prefer to give this beast a name and have the
> explicit value only once in my code. So I create a module "Constants"
> with something like
>
> k_B = 0.0083144708636327096
>
> The trouble is that k_B then becomes "Double" by default
Right. The good old monomorphism rule, I assume. Query: does this rule
ever make a programmer's job easier? Beats me.
> (or any other type I declare it to be).
Right. But: you can declare it to have type Fractional alpha => alpha,
which is the same type the constant has in the middle of an expression.
<snip>
Jon Cast