basvandijk / scientific

Arbitrary-precision floating-point numbers represented using scientific notation
BSD 3-Clause "New" or "Revised" License
73 stars 40 forks source link

Design of fromRationalRepetend #58

Closed seagreen closed 6 years ago

seagreen commented 6 years ago

Currently:

-- If the limit is not reached or no limit was specified @Right (s,
-- mbRepetendIx)@ will be returned.
<...>
fromRationalRepetend
    :: Maybe Int -- ^ Optional limit
    -> Rational
    -> Either (Scientific, Rational) (Scientific, Maybe Int)

This forces the caller to handle a Right result even the caller knows that will never happen because they used Nothing to specify no limit.

What about breaking it into two functions?

fromRationalFoo -- Not sure about the names
    :: Int -- ^ Limit
    -> Rational
    -> Either (Scientific, Rational) (Scientific, Maybe Int)

and

fromRationalBar :: Rational -> (Scientific, Maybe Int)
basvandijk commented 6 years ago

We should keep fromRationalRepetend in order not to break backwards compatibility. Some possible names for the two new functions:

Any preferences or other ideas?

seagreen commented 6 years ago

I like fromRationalRepetendLimited and fromRationalRepetendUnlimited, but any of the fromRationalRepetend* options sound good to me.

No other ideas at the moment, but I'll keep an eye out. Thanks for the great library!

basvandijk commented 6 years ago

fromRationalRepetendLimited and fromRationalRepetendUnlimited are added in scientific-0.3.6.1.

seagreen commented 6 years ago

Awesome! Thanks again for your hard work:)