Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

Add Safe vector indexing #17

Open
Ericson2314 opened this issue May 13, 2015 · 4 comments
Open

Add Safe vector indexing #17

Ericson2314 opened this issue May 13, 2015 · 4 comments

Comments

@Ericson2314
Copy link
Contributor

Just as we have pow2 block ram, etc, it would be nice if we had safe pow2 vector indexing.

I was just refactoring one of my processors to change the word size, and some bugs got caught with my tests instead of the type checker because I was using !!.

Maybe something like

(!!!) :: Integral i
      => KnownNat (2 ^ BitSize i)
      => Vec (2 ^ BitSize i) a
      -> i -> a
(!!!) = (CL.!!)

should go in CLaSH.Sized.Vector?

Feel free to suggest a different identifier if you like the idea, of course.

@christiaanb
Copy link
Member

Perhaps call it safeIndex?
I mean... there are already:
at
(!)
(!!)

I feel adding another indexing operator is going to make things more confusing, so I prefer a normal name.

@Ericson2314
Copy link
Contributor Author

Sure, that makes sense.

@bgamari
Copy link
Contributor

bgamari commented Jul 28, 2016

What remains to be done on this?

@christiaanb
Copy link
Member

Well, mostly we need to decide if we need more indexing operations than we already have for Vec: http://hackage.haskell.org/package/clash-prelude-0.10.10/docs/CLaSH-Sized-Vector.html#g:4, and then decide on a type signature.

As we currently have:

(!!) :: (KnownNat n, Enum i) => Vec n a -> i -> a
at :: SNat m -> Vec (m + (n + 1)) a -> a

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants