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

Modify Permutation to only allow actual permutations #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tomsmeding
Copy link

The original definition of the Permutation class allowed some lists that were not actually permutations, such as [1, 1]. This is because the constraints did require that all elements of the permutation array are valid indices into [1..n), but not that this mapping is bijective. Adding a reverse AllElem constraint corrects this.

Before this PR:

Prelude Data.Array.ShapedS> transpose @[1, 1] (fromList @[2, 3] @Double [1..6])
fromList @[3,3] [1.0,2.0,3.0,2.0,3.0,4.0,3.0,4.0,5.0]
Prelude Data.Array.ShapedS> transpose @[0, 0] (fromList @[2, 3] @Double [1..6])
fromList @[2,2] [1.0,4.0,4.0,*** Exception: index out of bounds (6,6)

After this PR, these invocations are rejected with a type error.

The original definition of the 'Permutation' class allowed some lists
that were not actually permutations, such as [1, 1].
Copy link

@Mikolaj Mikolaj left a comment

Choose a reason for hiding this comment

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

LGTM

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.

2 participants