-
Notifications
You must be signed in to change notification settings - Fork 27
Suggestions for some utility functions #72
Comments
http://hackage.haskell.org/package/clash-prelude-0.10.14/docs/CLaSH-Sized-Vector.html#v:backpermute is isomorphic to Edit: perhaps indexMapping :: KnownNat n => (Index n -> a) -> Vec n a
indexMapping f = imap (\i _ -> f i) (repeat ()) |
Would: multiplexor :: (KnownNat n, Enum sel) => Signal sel -> Vec n (Signal a) -> Signal a
multiplexor sel alts = (!!) <$> bundle alts <*> sel work for you? so you can write: multiplexor sels (0 :> xs :> ys :> zs :> Nil) Edit: of course you lose the exhaustiveness check you get in the original example |
|
The downside of using this vector multiplexer variant is that it depends on the implicit Enum ordering of the selection signal. And I would prefer explicit selectors to keep the code understandable. Maybe Vector could be made an instance of Representable Functor, with: tabulate :: (Index n -> a) -> Vec n a
index :: Vec n a ->(Index n -> a) Also the related type classes in Data.Key have a lot of functions that work on both lists and vectors, so that could be a way to simplify the transition from list based code. |
Looking at some clash code I found useful functions missing from the prelude.
(Index n -> a) -> Vec n a
The text was updated successfully, but these errors were encountered: