-
Notifications
You must be signed in to change notification settings - Fork 162
Add Clash.Sized.Vector.ToTuple
#2682
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
Clash.Sized.Vector.ToTuple
Clash.Sized.Vector.ToTuple
bc1599c
to
c33526e
Compare
5f9ff3a
to
7bb5668
Compare
Newer GHCs (mistakenly) emit warnings when pattern matching on `Vec`s, with neither `:>` nor `Cons` being able to prevent it. `vecToTuple` allows users to convert `Vec`s to tuples, sidestepping GHCs exhaustiveness checker while not compromising on safety. Nested tuples were considered as an alternative implementation, simplifying implementation and removing the need for `TemplateHaskell`. This would, however, compromise on user comfort while offering no expected real-world benefits.
7bb5668
to
ccf7915
Compare
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.
Was there a reason you use :>
instead of Cons
for the pattern match?
Discussed in the office: there is a difference in behavior. E.g. in the following: vecToTuplePat :: (Vec 2 a) -> (a, a)
vecToTuplePat (a1 :> a2 :> _) = (a1, a2)
-- True
pat :: Bool
pat = case vecToTuplePat (1 :> undefined) of
~(a, _) -> a `seq` True
vecToTupleCon :: (Vec 2 a) -> (a, a)
vecToTupleCon (a1 `Cons` a2 `Cons` _) = (a1, a2)
-- Bottom
con :: Bool
con = case vecToTupleCon (1 :> undefined) of
~(a, _) -> a `seq` True then |
@leonschoorl I applied your suggestions, thanks! |
Newer GHCs (mistakenly) emit warnings when pattern matching on `Vec`s, with neither `:>` nor `Cons` being able to prevent it. `vecToTuple` allows users to convert `Vec`s to tuples, sidestepping GHCs exhaustiveness checker while not compromising on safety. Nested tuples were considered as an alternative implementation, simplifying implementation and removing the need for `TemplateHaskell`. This would, however, compromise on user comfort while offering no expected real-world benefits. (cherry picked from commit c3d197f)
Newer GHCs (mistakenly) emit warnings when pattern matching on `Vec`s, with neither `:>` nor `Cons` being able to prevent it. `vecToTuple` allows users to convert `Vec`s to tuples, sidestepping GHCs exhaustiveness checker while not compromising on safety. Nested tuples were considered as an alternative implementation, simplifying implementation and removing the need for `TemplateHaskell`. This would, however, compromise on user comfort while offering no expected real-world benefits. (cherry picked from commit c3d197f)
Add `Clash.Sized.Vector.ToTuple` (copy #2682)
Newer GHCs (mistakenly) emit warnings when pattern matching on
Vec
s, with neither:>
norCons
being able to prevent it.vecToTuple
allows users to convertVec
s to tuples, sidestepping GHCs exhaustiveness checker while not compromising on safety.Nested tuples were considered as an alternative implementation, simplifying implementation and removing the need for
TemplateHaskell
. This would, however, compromise on user comfort while offering no expected real-world benefits.This is clearly a work around. Perhaps we should write a GHC plugin to circumvent these warnings (and depending on the solution upstream)?
Documentation
Still TODO: