-
Notifications
You must be signed in to change notification settings - Fork 40
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
Wrap output of splitIntoCoprimes into newtype #89
Comments
Style wise I like to use record fields to document what different positions
in a tuple mean. (One of my fave party tricks Is showing that you can mix
record and fast syntax. Though that’s not relevant here ;) )
…On Tue, Jan 2, 2018 at 5:16 PM Bodigrim ***@***.***> wrote:
Currently splitIntoCoprimes
<https://github.com/cartazio/arithmoi/blob/master/Math/NumberTheory/GCD.hs#L267>
guarantees certain properties of its output, but still returns a plain [(a,
b)]. Such return type is easily corruptible by other functions. It would
be much better to return something like
newtype Coprimes a b = Coprimes (Map a b)
The interface should not expose Coprimes constructor outside. Here is a
quick draft of API:
instance Semigroup (Coprimes a b) where ...
instance Monoid (Coprimes a b) where ...
insert :: a -> b -> Coprimes a b -> Coprimes a b
toList :: Coprimes a b -> [(a, b)]
------------------------------
Another vaguely related idea is to keep coprimes, which are known to be
prime, separately. This can potentially speed up certain computations,
especially with Prefactored. Like
data Coprimes a b = Coprimes (Map (Prime a) b) (Map a b)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#89>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAQwpoXD9xxn5LBbmRijtJQ7wlrCC1Gks5tGqrPgaJpZM4RRJFB>
.
|
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently splitIntoCoprimes guarantees certain properties of its output, but still returns a plain
[(a, b)]
. Such return type is easily corruptible by other functions. It would be much better to return something likeThe interface should not expose
Coprimes
constructor outside. Here is a quick draft of API:Another vaguely related idea is to keep coprimes, which are known to be prime, separately. This can potentially speed up certain computations, especially with
Prefactored
. LikeThe text was updated successfully, but these errors were encountered: