ekmett / linear

Low-dimensional linear algebra primitives for Haskell.
http://hackage.haskell.org/package/linear
Other
201 stars 50 forks source link

Is there interest in pattern synonyms for vector component swizzling? #85

Open ocharles opened 9 years ago

ocharles commented 9 years ago

Thinking of things such as

pattern X x <- (preview _x -> Just x)
pattern Y y <- (preview _y -> Just y)

probably with the corresponding review in as well. I say swizzling, as you could also have

pattern XY x y <- (preview _xy -> Just (x,y))
pattern YX y x <- (preview _yx -> Just (y,x))

If people think this is a useful addition, I will put together a pull request.

ekmett commented 9 years ago

These can skip the preview and just view.

pattern X x <- (view _x -> x)

I have to admit they make me rather uncomfortable as I prefer pattern synonyms that don't lose information.

I'm withholding judgment for now until others weigh in for a bit.

ocharles commented 9 years ago

They came out of building a 2D platformer where I wanted to decompose motion along the X and Y axis - it was quite handy to be able to just pattern match the respective components out of the velocity vector. That said, there's no reason these synonyms can't live in that project rather than linear. Let's keep it open and see if anyone else has thoughts.

ekmett commented 9 years ago

Sounds good to me.