purescript-fast-vect icon indicating copy to clipboard operation
purescript-fast-vect copied to clipboard

`Vect` to nested tuple conversion

Open paluh opened this issue 2 years ago • 2 comments

Hi, thanks a lot for building this lib! :-)

I find it useful to be able to deconstruct a Vect i a value into a tuple. I mean:

a /\ b /\ c = vectTuple $ 1 : 2 : 3 : empty

Do you think it would be valuable addition?

P.S. I'm using this class to handle this - so this is my possible upcoming PR:

class VectTuple vect tuple | vect -> tuple where
  vectTuple :: vect -> tuple

instance VectTuple (Vect 1 a) a where
  vectTuple vect = head vect
else instance
  ( Add 1 i' i
  , VectTuple (Vect i' a) tpl
  , Compare i' NegOne GT
  , Compare i NegOne GT
  , Compare i 0 GT
  ) =>
  VectTuple (Vect i a) (a /\ tpl) where
  vectTuple vect = head vect /\ vectTuple ((drop (Proxy :: Proxy 1) vect) :: Vect i' a)

paluh avatar Apr 23 '23 17:04 paluh

I see no reason why not. The only thing may be that it is probably only really usable for small vectors, but I guess this could be a comment

sigma-andex avatar Apr 23 '23 18:04 sigma-andex

Yeah, looks good to me too

artemisSystem avatar Apr 23 '23 19:04 artemisSystem