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

Wrap output of splitIntoCoprimes into newtype #89

Closed
Bodigrim opened this issue Jan 2, 2018 · 1 comment
Closed

Wrap output of splitIntoCoprimes into newtype #89

Bodigrim opened this issue Jan 2, 2018 · 1 comment

Comments

@Bodigrim
Copy link
Owner

Bodigrim commented Jan 2, 2018

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 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)
@cartazio
Copy link
Collaborator

cartazio commented Jan 4, 2018 via email

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

No branches or pull requests

2 participants