Skip to content

Conversation

treeowl
Copy link
Contributor

@treeowl treeowl commented Nov 13, 2014

NOTE: This is not tested yet!

Implement fmap/coerce rules for Map, Sequence, and Tree. One concern:
unfortunately, implementing the RULES requires importing Data.Coerce,
which forces the LANGUAGE to be turned from Safe to Trustworthy. This
is rather sad. An alternative would be to do this in another module, but
orphan rules are not so lovely either.

@foxik
Copy link
Contributor

foxik commented Nov 14, 2014

Thanks.

Does the "This is not tested" mean we should wait before you test it?

Also, in Data.Map.Strict and Data.Map.Base -- we are providing trivial MIN_VERSION_base if it is unavailable. In Data.Map.Base, could you move the existing MIN_VERSION_base definition just before comments before module definitions (as in Data.Sequence and Data.Tree; currently it is defined after you use it to guard import of Data.Coerce) and add it to Data.Map.Strict?

@treeowl
Copy link
Contributor Author

treeowl commented Nov 14, 2014

It actually means I haven't set up the bleeding-edge cabal to be able to test it. If someone else wants to try (compiling with a recent GHC 7.9 to activate the special code) that would be great. Otherwise, I'll get to it when I have a chance. I can definitely move and add MIN_VERSION_base as requested.

@treeowl treeowl force-pushed the seqfmapcoerce branch 2 times, most recently from bb6a34a to 34e82aa Compare November 16, 2014 19:35
@treeowl
Copy link
Contributor Author

treeowl commented Nov 16, 2014

I've tested the new code for Seq, adapting some code by @nomeata, and it works. I haven't tested the others yet. I also have yet to implement the rule for IntMap.

@@ -1660,6 +1662,14 @@ mapEitherWithKey f0 t0 = toPair $ go f0 t0
map :: (a -> b) -> Map k a -> Map k b
map _ Tip = Tip
map f (Bin sx kx x l r) = Bin sx kx (f x) (map f l) (map f r)
#if MIN_VERSION_base(4,8,0)
-- Safe coercions were introduced in 4.7.0, but I am not sure if they played
-- well enough with RULES to do what we want.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don’t think much changed with regard to RULES and coercion since 7.8, and even if the rule does not fire it is not a problem, I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

I stand corrected. There were changes, and "map/coere" was also only added in base 4.8. So this can stay as it is.

Implement fmap/coerce rules for Map, Sequence, and Tree. One concern:
unfortunately, implementing the RULES forces the LANGUAGE to be turned
from Safe to Trustworthy.  This is rather sad. An alternative would be
to do this in another module, but orphan rules are not so lovely either.
@treeowl
Copy link
Contributor Author

treeowl commented Nov 18, 2014

OK, I think this is ready to go, for what it is. I've tested all three containers implemented. I'll open a new pull request later, once I've done something with IntMap.

foxik added a commit that referenced this pull request Nov 18, 2014
@foxik foxik merged commit e083f68 into haskell:master Nov 18, 2014
@foxik
Copy link
Contributor

foxik commented Nov 18, 2014

Thanks.

@treeowl treeowl deleted the seqfmapcoerce branch November 18, 2014 14:13
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