Skip to content

Conversation

@Divesh-Otwani
Copy link
Contributor

@Divesh-Otwani Divesh-Otwani commented Jan 5, 2021

Summary

This PR adds to push arrays:

Depends on #287.

Things I don't fully understand

  • I don't fully understand the role of linear types here. Is it just to have the linear monoid so that the type necessarily writes each element once (and that in the allocation, we use destination arrays). Can we come up with a concise statement of how we apply linear types?
  • Aren't we still missing the "use each index only once" property of pull arrays?

@Divesh-Otwani Divesh-Otwani requested a review from aspiwack January 5, 2021 00:29
@Divesh-Otwani Divesh-Otwani changed the base branch from master to better-push-arrays-2 January 5, 2021 00:29
@Divesh-Otwani Divesh-Otwani requested a review from utdemir January 5, 2021 00:32
@b-mehta
Copy link
Collaborator

b-mehta commented Jan 5, 2021

This and part 1 looks promising to me! I think foldWith looks sensible, and if unzip can be made to work then I'd be much more convinced. Nice stuff!

foldWith f (Array k) = k f

unzip :: Array (a,b) %1-> (Array a, Array b)
unzip = undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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).

Copy link
Contributor Author

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.

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

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.

{-# OPTIONS_GHC -Wno-orphans #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeInType #-}
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remnants from my testing.

@@ -1,5 +1,7 @@
{-# OPTIONS_GHC -Wno-orphans #-}
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remnants from my testing.

@Divesh-Otwani Divesh-Otwani force-pushed the push-arrays/fold branch 2 times, most recently from d14273f to 5c08147 Compare January 5, 2021 18:25
@Divesh-Otwani Divesh-Otwani marked this pull request as ready for review January 5, 2021 18:29
Base automatically changed from better-push-arrays-2 to master January 6, 2021 15:44
@dpulls
Copy link

dpulls bot commented Jan 6, 2021

🎉 All dependencies have been resolved !

@Divesh-Otwani Divesh-Otwani merged commit ea89efc into master Jan 7, 2021
@Divesh-Otwani Divesh-Otwani deleted the push-arrays/fold branch January 7, 2021 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Push Arrays Construction of Push Arrays

5 participants