-
Notifications
You must be signed in to change notification settings - Fork 156
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
Feature offer: n-ary product type #550
Comments
I don't understand what the advantages are over using tuples. Could you expand on that? Thanks! |
I guess it allows things like mapping type-level functions over all the arguments. So you could eg specify that you increase the number of elements of every Vector in the product by one. So e.g.
|
@martijnbastiaan : exactly as I thought, mapping type-level functions: https://github.com/gergoerdi/clash-utils/blob/f9c57526381892b8109e72f1724faca42f8ba544/src-clash/Cactus/Clash/Counters.hs#L88-L92 |
@gergoerdi I'm interested: apparently you had a need to write and use it, so I assume eventually other Haskellers will as well. Even though it might not be super friendly to people new to Haskell, I think that's kind of a non-argument: It's not like we'll suddenly be using this n-ary product instead of regular tuples in all of our documentation. In addition it solves some pet peeves of mine wrt to tuples:
One question w.r.t. to the |
Maybe we could put things like this in an extra package |
So I see @christiaanb has already answered the question on motivation: in my case, I originally wanted something that, given a counter structure like |
Yes you are in good company for saying this; however, the reality is that the GHC type checker barfs on the
(and no, this doesn't go away even with an explicitly-polymorphic recursion a la
|
Ooh I am just now realizing that for the nicest possible type for my product-of-sums ripple counter, I would probably also want n-ary sums, so that something like
would be mapped to
|
In case anyone is interested in this, I have now implemented the above with product-of-sum types: see https://github.com/gergoerdi/clash-utils/blob/9e333b3482788220d6f37e1018f57f117a58826f/src-clash/Cactus/Clash/Counters.hs and as an example of use: https://github.com/gergoerdi/clash-utils/blob/9e333b3482788220d6f37e1018f57f117a58826f/src-clash/Cactus/Clash/VGA.hs
|
Very cool @gergoerdi ! I wanted to let you know your contributions are greatly appreciated, even though we're a bit slow to respond from time to time.. |
This is the dual of a feature request: I am offering the below module for consideration into inclusion in
clash-prelude
. It is not in the form of a pull request because I'd like to know first if this is something you guys would want.It is an n-ary product type:
Product [t1, t2, t3]
is isomorphic to the tuple type(t1, t2, t3)
. My motivation for it is using it for a product-of-sums (sic!) ripple counter as can be seen here: this, in turn, allows me to write a VGA signal generator as simply asgiving me
vgaX :: Signal _ (Maybe (Index w))
andvgaHSync :: Signal _ Bit
, etc. from a type-level VGA mode specification like(see the full VGA implementation here)
So anyway, is the below code something that would be a good idea to add to
clash-prelude
?The text was updated successfully, but these errors were encountered: