statistics icon indicating copy to clipboard operation
statistics copied to clipboard

Add function which wotk withy Foldable containers

Open Shimuuar opened this issue 7 years ago • 2 comments

All API of Statistics.Sample works only with vectors. It would be handy to add functions for working with containers implementing Foldable 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

Shimuuar avatar Jul 24 '18 18:07 Shimuuar

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?

GregorySchwartz avatar Feb 20 '19 17:02 GregorySchwartz

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

Shimuuar avatar Mar 06 '19 18:03 Shimuuar