ekmett / linear

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

Why is `_Point` an `Iso'`, rather than a type-changing `Iso`? #171

Closed ocharles closed 1 year ago

ocharles commented 2 years ago

Is there any reason _Point can't change the type of vector-space? Naturally we can't change the dimensions, but changing the underlying element type?

RyanGlScott commented 2 years ago

(I've transferred this issue to linear, since I think that was the intended repo to open the issue against.)

ocharles commented 2 years ago

Whoops, not sure how that happened! Thanks.

RyanGlScott commented 2 years ago

As far as the question raised in the issue goes, this package does seem to have a convention of using simple Lenses and Isos everywhere. I'm not sure if this is a deliberate choice or just a coincidence, however—I'd have to let someone more familiar with the history of the library chime in.

ocharles commented 2 years ago

@ekmett Could I get your input here? I just ran into this again wanting to write:

over _Point (view _xy)

but that doesn't type check. Using over coerced (view _xy) doesn't work here because coerced is too general.

ekmett commented 2 years ago

I think there was an example where the type change caused some inference pain, but it was super early on when the combinators for extracting from a lens was too polymorphic, so I think it'd be fine to change to an Iso.

ocharles commented 2 years ago

Cool I'll open a PR