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

instance Traversable LinearRing violates the Traversable laws #21

Open
tysonzero opened this issue Nov 15, 2018 · 2 comments
Open

instance Traversable LinearRing violates the Traversable laws #21

tysonzero opened this issue Nov 15, 2018 · 2 comments

Comments

@tysonzero
Copy link

Specifically the composition law:

traverse (Compose . fmap g . f) = Compose . fmap (traverse g) . traverse f
traverse (Compose . fmap g . f) x = Compose . fmap (traverse g) . traverse f $ x
f = enumFromTo 1
g = mfilter (> 1) . Just
x = LinearRing 2 2 2 (fromList [])
traverse (Compose . fmap g . f) x
Compose [Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Just (LinearRing 2 2 2 (fromList []))]
Compose . fmap (traverse g) . traverse f $ x
Compose [Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Just (LinearRing 2 2 2 (fromList [])),Just (LinearRing 2 2 2 (fromList []))]
@newmana
Copy link
Collaborator

newmana commented Nov 15, 2018

This is interesting because I guess it's because the traversable instance tries to close the LinearRing. I imagine the Foldable instance will have a similar issue.

@tysonzero
Copy link
Author

tysonzero commented Nov 15, 2018

The Foldable instance is technically lawful, because Foldable has no laws (besides free theorem laws that will obviously hold).

Now if you did fix the Traversable instance to avoid the "closing" (you are correct that is the reason), then a different Traversable law would be broken, the one that requires Traversable and Foldable to agree.

So if you do want to have a lawful Traversable instance then yeah the Foldable instance would have to be changed as well.

I would say its reasonable to drop the "closing" part, as its (IMO) perfectly reasonable for (0, 0) (0, 1) (1, 0) to represent a triangle. Although if you do I would suggest dropping it in most places, such as fromList.

Although I realize it has become pretty standard to represent rings with a duplicated point at the end rather than using the more Haskell-like approach of using the type/constructor to indicate whether you have a LineString or a LinearRing.

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