For me, an integer set seems to be a foldable data structure.
Why is Data.IntSet not an instance of Foldable?
My actual intention is to use find on an IntSet.
How can I implement find for Data.IntSet?
For me, an integer set seems to be a foldable data structure.
Why is Data.IntSet not an instance of Foldable?
My actual intention is to use find on an IntSet.
How can I implement find for Data.IntSet?
Copyright © 2021 Jogjafile Inc.
IntSetcan't beFoldablefrombasepackage because it doesn't have kind* -> *.In simple words, to be instance of
Foldablefrombaseyou data type should be parametrized by some type variable. If you want to use some operation onIntSetyou should use some function fromData.IntSetmodule where all specialized versions implemented.But I want to add that there exist version of
FoldablewhichIntSetcan instantiate (and we actually did this in our library and this was done earlier withMonoFoldable). You just need to implement your abstractions properly:UPDATE (adding
findby request):You can't implement
find :: (a -> Bool) -> IntSet -> Maybe abecause ofatype variable. Can you answer question «What isa?»?IntSetis not polymorphic container. It contains onlyInts. So maximum you can implement isfind :: (Int -> Bool) -> IntSet -> Maybe Int. And there's no efficient way to implement this function, only by convertingIntSetto list like this: