-
Notifications
You must be signed in to change notification settings - Fork 40
Improve make
/Make
implementation for Data.V.Linear
#364
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
Conversation
I set the base of this PR to tbagrel1/dupable-new-impl, so as to reduce clutter in the diff pane, but the idea is to merge this one only after that tbagrel1/dupable-new-impl has been merged into |
I know what this PR is about. Today. But please don't make a PR without a description. I'm not the only one who is to read these. And even if this was just for you and me, we may want to revisit the PR in the future to remember why we did X and Y, without an apt description, it becomes impossible. |
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.
Fix the documentation then merge.
We will want to have some tests of the staging of both elim
-s as well as make
in the test suite before we make a release.
src/Data/V/Linear/Internal.hs
Outdated
-- The idea behind 'Make' \/ @make\'@ \/ 'make' is the following: | ||
-- | ||
-- @f@ takes @m@ values of type @a@, but returns a @'V' n a@ (with @n@ ≥ @m@), | ||
-- so the @n - m@ missing values must be supplied via the accumulator. | ||
-- | ||
-- @make\'@ is initially called with @m = n@ via 'make', and as @m@ decreases, | ||
-- the number of lambda on the left increases and the captured values are put | ||
-- in the accumulator | ||
-- (@V[ ... ] \<\>@ represents the "extend" operation for 'V'): | ||
-- | ||
-- > make @n | ||
-- > --> make' @n @n (V[] <>) | ||
-- > --> λx. make' @(n - 1) @n (V[x] <>) | ||
-- > --> λx. λy. make' @(n - 2) @n (V[x, y] <>) | ||
-- > --> ... | ||
-- > --> λx. λy. ... λz. make' @0 @n (V[x, y, ... z] <>) -- make' @0 @n f = f V[] | ||
-- > --> λx. λy. ... λz. V[x, y, ... z] |
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 think that this documentation should be on the make
function, not the Make
class.
Plus it speaks of make'
, which isn't exported. Let's avoid this. If you need to document the implementation, do so outside of the docstring, in regular comments.
Remember to give instantiations of the type of make
with concrete values. Examples are very helpful to disentangle very general types.
0b07dc7
to
6e26c50
Compare
V n a
represents vector havingn
elements of typea
. Such a vector can be built using themake
function, takingn
linear arguments of typea
, and returning aV n a
.At the moment,
make
uses a lot of type-level machinery aroundNat
s, and is implemented in a way such that it cannot be inlined; even ifn
is compile-time known.With #360 (now merged), the
Data.V.Linear
module has been overhauled, and theelim
function has been rewritten to be inlinable.The aim of this PR is to provide an efficient
make
implementation using typeclasses so as to make it inlinable whenn
is known at compile-time. It also adds more symmetry betweenmake
andelim
, and allows us to get rid of a lot of internal helper functions.