Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Number-related code from deprecated purescript-globals into this repo #12

Merged
merged 21 commits into from
Nov 12, 2020
Merged

Port Number-related code from deprecated purescript-globals into this repo #12

merged 21 commits into from
Nov 12, 2020

Conversation

JordanMartinez
Copy link
Contributor

@JordanMartinez JordanMartinez commented Oct 24, 2020

@JordanMartinez
Copy link
Contributor Author

CI passes. Waiting for review.

@@ -5,12 +5,34 @@ module Data.Number
, isNaN
, infinity
, isFinite
, readInt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes to export readInt from this module, as readInt doesn't really have much to do with numbers. Additionally, Data.Int already provides a fromString which does what we want.

Copy link
Contributor Author

@JordanMartinez JordanMartinez Nov 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it does provide fromString, readInt can parse a String into a specified base. Should we port this function (albeit under a different name) to purescript-integers? Or should it be dropped altogether?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I think we should just drop it for now; I think we can add integer parsing in a specified base to purescript-integers if and when someone asks for it.

@@ -5,12 +5,34 @@ module Data.Number
, isNaN
, infinity
, isFinite
, readInt
, readFloat
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense to export this function, as it's just a less safe version of fromString.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@@ -5,12 +5,34 @@ module Data.Number
, isNaN
, infinity
, isFinite
, readInt
, readFloat
, toFixed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not export toFixed, toExponential, or toPrecision here, since formatting numbers is already covered by Data.Number.Format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

-- |
-- | May throw RangeError if the number of digits is not within the allowed range
-- | (standard precision range is 0 to 20, but implementations may change it)
foreign import unsafeToFixed :: Int -> Number -> String
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to export these either, since they're more JS-specific in how they handle errors, whereas the core libraries ought to be backend-independent as far as is possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Should this be moved to a separate repo outside of core? Or do you think it's fine to drop them entirely?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to drop them entirely: it's hard for me to imagine a situation where you'd want these functions to be able to throw.

@JordanMartinez
Copy link
Contributor Author

I've updated the code to account for @hdgarrood's feedback (thanks!) Let me know whether I need to make any other changes.

Comment on lines 6 to 14
import Effect (Effect)
import Effect.Console (log)

import Data.Number (isFinite, infinity,
nan, isNaN, fromString)
import Data.Number.Format (precision, fixed, exponential, toStringWith,
toString)
import Data.Number.Approximate (Fraction(..), Tolerance(..), eqRelative,
eqAbsolute, (≅), (≇))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't really matter, but I don't think we format imports like this anywhere else and for consistency's sake it might be nice to format them on one line.

The same is true of these non-ASCII operators from Data.Number.Approximate -- but I suppose we're keeping those due to them being a breaking change to remove?

Either way it's no reason to block this from merging, but I wanted to draw attention here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept those as is to help show that the port didn't add/remove any code.

Other than that, I agree that the imports should be reduced to one line again. I'll add a commit that does that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would usually prefer not to introduce non-ASCII operators in the core libraries, but causing a breaking change by removing them is definitely worse in my book.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... Yeah, I'm not sure about the non-ASCII syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants