-
Notifications
You must be signed in to change notification settings - Fork 52
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
Direction of foldl
library
#10
Comments
I think there're a lot of thing to be explored. So it's way too early to say that design is frozen. Here is most important in my opinion:
With regard to profunctors I'm not sure that instance is useful enough to warrant a dependency. And if we add monads to fold it becomes impossible to define comonad instances. We lose If we to add dependency on |
The question of dependencies was somewhat impeding my own thinking what it might be useful to do. A lot seemed to turn on whether or how you were going to introduce the It is slightly annoying, but maybe one should concede that there will be a couple of packages; the trouble I had thinking about this in the past was how to divide them. One of them might be something like Another I do think that the pre-packaged folds are what makes this library distinctive and potentially widely used. The present library has a rather austere collection of folds but these are enough to impart the fundamental idea. One pedagogically important point is missing -- namely the obvious one that you apply the same Folds to diverse sequential types. It might make sense to add I havent thought about it but there will obviously be fold functions for things like |
Actually I consider foldl as possible foundation for calculation of mean/variance etc in statistics package. Current versions could only work with vectors which isn't satisfactory. |
Yes, one of the things on my TODO list is to create numerically stable statistics like those found in the |
I've created |
By the way, I'm not sure a comonad instance for
It has an obvious
i.e.,
which is the 'co-church' encoding corresponding to the 'normal' recursive type:
How do we insert a monadic aspect into a standard recursive type like that? Most respectably, I guess:
and less respectably:
I am trying to arrange an obvious similarity between Anyway, the non-recursive encodings corresponding to those two choices are
and
respectively. Working back now toward more familiar types, these in turn are equivalent to
and
respectively. The latter of these is then basically
Reasons favoring something like Or anyway, I was wondering about this. |
On the other hand it's possible to have something comonad-like with |
@Shimuuar Perhaps a comonad in the category of Kleisli arrows over |
No idea. I'm not well versed in generalized abstract nonsence (-: |
I see; I don't know how these histogram folds work. I take it the problem with a |
So, the |
@michaelt On second thought it would be more problem of style. Consider following code:
Here we're forced to wrap return type into monad. It's more of incovenience but I don't think comonad instance worth it. I think this data type does form a comonad as you porposed. Problem arise with cokleisli arrows. They have type: |
Yeah, I agree that the I also wanted to mention that I just setup the https://github.com/Gabriel439/Haskell-Pipes-Foldl-Library Here's some example code for how you would create a import Control.Applicative (pure)
import Lens.Family ((^.))
import Control.Foldl (sum)
import Pipes.Foldl (fold, folds)
import Pipes.ByteString (stdin, lines)
import Prelude hiding (lines, sum)
main = do
numLines <- fold sum (folds (pure 1) (stdin ^. lines))
print numLines Note that if you added a |
@Shimuuar, my remark above wasn't really aimed at a comonad instance but at possible simplification, perhaps in aid of assimilating |
@Gabriel439 I made a similar package and a few others, in order to think out how dependencies were supposed to work. Here are a couple of the others, for what they're worth https://github.com/michaelt/foldl-conduit https://github.com/michaelt/foldl-instances The second suggests a type class like the one Shimuuar envisaged somewhere in the discussion. The conduit one I had only started thinking about; it is just holding the place of something outside the system, for purposes of thinking about dependencies. |
Fold vs FoldMWell it's always possible to convert
It means that we can easily replace Data sample representationRecently I found rather nice way to encode any kind of data sample:
It encapsulates both data and folding function. It also form monoid so it's possible to concatentate any container whatever data representation it uses.
Now it's possible to define type class for arbitrary data sample:
So far I ignored monadic folds but it's quite simple to accomodate them too. Since we require code to work with any monad we can specialize to Identity and work with pure folds just as well.
|
So I just added This also inadvertently solved another problem. The main reason I had two separate types was that I thought there was no convenient way to unpack a I rememember @michaelt mentioned previously that he had profiled
|
I'm writing a separate comment to address some points brought up by @Shimuuar in his first comment that I didn't have time to address until now.
Can you elaborate on this? Wouldn't
Just have those folds take the mean estimate as the parameter and let the user decide how to derive that estimate (either by folding the data in a separate pass themselves or by obtaining the estimate through some other means).
Alright. I still have an issue for this open because I will probably add this.
I've already addressed this by adding monomorphic folds for
Right now the balance I'm trying to strike dependency-wise for
Well, what I think I will do is just upgrade |
Regarding |
Never mind, I will provide separate |
On 12/29/2013 12:02 AM, Gabriel Gonzalez wrote:
It's actually quite powerful thing. It allows to process different It however makes thing much more complicated.
|
On 12/29/2013 12:04 AM, Gabriel Gonzalez wrote:
Monomorphic folds (for bytestring/text/etc.) allows to apply different |
I understand now. This is only possible if we change the internal implementation of
If the accumulator is a
Can you give me an idea of what API you had in mind?
What I was asking is what the purpose of the newtype was. If you supplied a
I'm very reluctant to define new type classes unless there is a very compelling reason because type classes require a lot of buy-in from the rest of the Haskell ecosystem. The other problem is that you are asking for what is essentially the |
On 12/29/2013 04:54 AM, Gabriel Gonzalez wrote:
Since we are storing current state there's no space leak and it's
It's possilbe to chain such folds. It's actually a reader monad.
Sample arose during experimentation with such N-pass folds. I tried to But most severe problem is not N-pass folds. It's entirely possible to |
So one problem I just realized last night is that if you try to make folds parallelizable you can't make them effectful any longer since you have to preserve the ordering of effects. |
I also found it difficult to formulate meaningful law for effectful parallelizable folds. There's another concern. I think it's not reasonable to require user to define merge function if all he want some aad hoc fold. I think only way is to create several fold types. |
Well, I would like to keep |
Can't To end users, the duplication of libs with common goals as exemplified by At least at first and second glance ;-) That said, |
So the first problem is that However, the nice thing about The other thing is that |
I do agree about the teaching aspect. Reading your source is quite approchable in general. Are you planning to add a |
So my plan is to fake |
I will go ahead and close this issue. What I concluded from this discussion is that:
Anything more complicated than that should probably go into a derived library. The exceptions are functions like |
This is partially an update and partially a solicitation for opinions on certain design choices for this library.
So I've designed
pipes
libraries to not directlyl depend onfoldl
so that I can be much freer about adding dependencies tofoldl
. The reason why is that these other issues have indicated thatfoldl
may require many other dependencies including, but not limited to:profunctors
comonad
text
andbytestring
(to provide convenience folds for these types)I wanted to see if people would be fine with the above dependencies or if they had other dependencies that they thought might be worth adding. I'd like to develop this into a more fully featured library.
Also, I've decided to freeze the core type (except perhaps to unify
FoldM
andFold
into a single type as @michaelt suggested), so there won't be any new changes on that front. I'm pretty happy with its current functionality.The text was updated successfully, but these errors were encountered: