roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.47k stars 315 forks source link

Rename `Float a` to `Frac a` #2848

Closed rtfeldman closed 2 years ago

rtfeldman commented 2 years ago

We currently have a Float a numeric type (e.g. Num.sqrt : Float a -> Float a) which actually represents more than just floating-point numbers; it also represents Dec, which is fixed-point instead of floating-point.

We should rename the Num.Float type to Num.Frac instead (short for fraction, since all the numbers it represents are fractions.)

nikitamounier commented 2 years ago

Would Num.pi and Num.e/ Num.exp(...) be of type Num.Frac too? Because those technically aren't rational numbers – they can't be represented by a fraction. What about Num.Real?

This makes sense to me from a domain modelling standpoint, since Real a would be used when defining functions, so it makes sense that the one who is creating the function should be thinking about the set of numbers they intend to support.

rtfeldman commented 2 years ago

All of those constants are fractional approximations; Num.pi is not equal to the mathematical constant pi! 😄

nikitamounier commented 2 years ago

Yeah, good point. Num.Real is probably too academic / pedantic anyways.