-
Notifications
You must be signed in to change notification settings - Fork 40
Push arrays/fold #288
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
Push arrays/fold #288
Conversation
|
This and part 1 looks promising to me! I think |
src/Data/Array/Polarized/Push.hs
Outdated
| foldWith f (Array k) = k f | ||
|
|
||
| unzip :: Array (a,b) %1-> (Array a, Array b) | ||
| unzip = undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| unzip = undefined | |
| unzip (Array k) = k (\(a, b) -> (singleton a, singleton b)) |
This kind of make sense to me, but I'm unsure (both semantically and performance-wise).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's very clever and I feel dumb for not coming up with it after messing with it for a while, lol 😸
It does make sense: k is something that takes something that writes an a to a monoid that represents a composable way to write an a to a cell of an array. Here, k takes something that changes (a,b) to a monoidal-computation that writes an (a,b) to a cell of an array.
This implementation in words says "a way to write each pair of (a,b) into a monoidal writing-computation is to have a pair of monoidal writing-computations". If you give this to k it will make a bunch of pairs of singletons and concatenate them.
src/Data/Array/Polarized/Push.hs
Outdated
| cons x (Array k) = Array (\writeA -> (writeA x) <> (k writeA)) | ||
|
|
||
| foldWith :: Monoid b => (a -> b) -> Array a %1-> b | ||
| foldWith f (Array k) = k f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is foldMap (specialized to Array and with a linear arrow), so I think we should call it that.
The Foldable/Traversable issues are likely relevant, but those assume the first parameter to be linear too. Bit unfortunate that we don't have a typeclass for this.
src/Data/Array/Polarized/Push.hs
Outdated
| {-# OPTIONS_GHC -Wno-orphans #-} | ||
| {-# LANGUAGE DerivingVia #-} | ||
| {-# LANGUAGE GADTs #-} | ||
| {-# LANGUAGE TypeInType #-} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remnants from my testing.
src/Data/Array/Polarized/Push.hs
Outdated
| @@ -1,5 +1,7 @@ | |||
| {-# OPTIONS_GHC -Wno-orphans #-} | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also doesn't seem to be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remnants from my testing.
d14273f to
5c08147
Compare
5c08147 to
5b83d75
Compare
5b83d75 to
43d4af5
Compare
|
🎉 All dependencies have been resolved ! |
Summary
This PR adds to push arrays:
Depends on #287.
Things I don't fully understand