Open Shimuuar opened 6 years ago
Just curious, vectors already have a foldable instance, so couldn't the entire library be generalized except for functions (I'm not sure which) which use very specific, non-generalizable techniques?
Only boxed ones do. Problem is Foldable
insists that we should be able to work with containers containing any data type. Here is fold from Foldable: foldl :: (b -> a -> b) -> b -> t a -> b
and here is one from unboxed vectors: foldl :: Unbox a => (b -> a -> b) -> b -> Vector a -> b
. Here we have constaint on element of vector and it precludes as from defining Foldable instance.
In order to do anything interesting with vectors (except boxed ones) we generally we need to constrain their elements. In general haskell doesn't play very well with polymorphic unboxed values
All API of
Statistics.Sample
works only with vectors. It would be handy to add functions for working with containers implementingFoldable
as well.One downside is duplication of the API. It will only become worse if such duplication is extended to other modules. It would be nice to avoid such dulication but I don't know any way to generalize both vector and Foldable API