Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function which wotk withy Foldable containers #146

Open
Shimuuar opened this issue Jul 24, 2018 · 2 comments
Open

Add function which wotk withy Foldable containers #146

Shimuuar opened this issue Jul 24, 2018 · 2 comments

Comments

@Shimuuar
Copy link
Collaborator

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
Copy link

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
Copy link
Collaborator Author

Shimuuar commented Mar 6, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants