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.
IntSet
can't beFoldable
frombase
package because it doesn't have kind* -> *
.In simple words, to be instance of
Foldable
frombase
you data type should be parametrized by some type variable. If you want to use some operation onIntSet
you should use some function fromData.IntSet
module where all specialized versions implemented.But I want to add that there exist version of
Foldable
whichIntSet
can 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
find
by request):You can't implement
find :: (a -> Bool) -> IntSet -> Maybe a
because ofa
type variable. Can you answer question «What isa
?»?IntSet
is not polymorphic container. It contains onlyInt
s. So maximum you can implement isfind :: (Int -> Bool) -> IntSet -> Maybe Int
. And there's no efficient way to implement this function, only by convertingIntSet
to list like this: