haskell / statistics

A fast, high quality library for computing with statistics in Haskell.
http://hackage.haskell.org/package/statistics
BSD 2-Clause "Simplified" License
300 stars 67 forks source link

Add function which wotk withy Foldable containers #146

Open Shimuuar opened 6 years ago

Shimuuar commented 6 years ago

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

GregorySchwartz commented 5 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?

Shimuuar commented 5 years ago

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