Skip to content
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

Add Counter a => Counter (Vec n a) instance #2787 #2788

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

gergoerdi
Copy link
Contributor

Fixes: #2787

@leonschoorl
Copy link
Member

leonschoorl commented Aug 19, 2024

I think it would be good if the instance came with a comment about the endianness.
Something like

-- | Counters on tuples increment from right-to-left. This makes sense from the
-- perspective of LSB/MSB; MSB is on the left-hand-side and LSB is on the
-- right-hand-side in other Clash types.
--
-- >>> type T = (Unsigned 2, Index 2, Index 2)
-- >>> countSucc @T (0, 0, 0)
-- (0,0,1)
-- >>> countSucc @T (0, 0, 1)
-- (0,1,0)
-- >>> countSucc @T (0, 1, 0)
-- (0,1,1)
-- >>> countSucc @T (0, 1, 1)
-- (1,0,0)

I like examples like that, because I can never remember which way round is supposed to be big or little.

@leonschoorl
Copy link
Member

leonschoorl commented Aug 19, 2024

Also this endianness you implemented now is the "right" one I think.
Because it is consistent with the view encoded in BitPack/Clash.Class.BitPack.BitIndex:

clashi> countSucc @(Vec 3 Bit) (0 :> 0 :> 0 :> Nil)
0 :> 0 :> 1 :> Nil
clashi> msb @(Vec 3 Bit) (0 :> 0 :> 1 :> Nil)
0
clashi> lsb @(Vec 3 Bit) (0 :> 0 :> 1 :> Nil)
1

@martijnbastiaan
Copy link
Member

@kloonbot run_ci ca3cba0

Copy link
Member

@martijnbastiaan martijnbastiaan left a comment

Choose a reason for hiding this comment

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

Agreed with @leonschoorl on the examples / doctests. Other than that, LGTM.

@gergoerdi gergoerdi force-pushed the issue-2787 branch 3 times, most recently from 4d67c5f to 83ce499 Compare August 27, 2024 11:37
@gergoerdi
Copy link
Contributor Author

Where are we on this?

@martijnbastiaan
Copy link
Member

@kloonbot run_ci ec242f6

@martijnbastiaan
Copy link
Member

I'm okay with this if CI is.

@DigitalBrains1 DigitalBrains1 merged commit 3b755b9 into clash-lang:master Sep 24, 2024
15 checks passed
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.

Counter for Vectors
4 participants