[Haskell-cafe] linear: instance Additive (Point f) ??

Edward Kmett ekmett at gmail.com
Wed Mar 18 17:23:38 UTC 2015


On Tue, Mar 17, 2015 at 10:41 PM, Brent Yorgey <byorgey at gmail.com> wrote:

> I have EXACTLY the same question.  We recently switched from vector-space
> to linear for diagrams.  There are quite a lot of reasons why this works
> really well for us.  But I was very sad to find that we can now add points,
> which indeed we do not want to be able to do.  At least there are still
> different types for points and vectors, which allows transformations like
> 'translate' to act on them differently, which I actually find to be much
> more critical from a correctness point of view.
>
> I have had a brief explanation, but I forget the exact details.  Something
> about 'Additive' not really being about 'additive groups' but instead being
> a superclass of Applicative.  I remember being convinced at least that it's
> a "pick your poison" sort of choice, i.e. removing the Additive instance
> for Point would make certain other things ugly/annoying.  Hopefully someone
> else can chime in with more detail.
>
>
The name Additive is a bit of a misnomer, like you said. The real reason it
exists is to support matrix operations on both sparse/dense matrices.

Matrix multiplication looks like:

(!*!) :: (Functor m, Foldable t, Additive t, Additive n, Num a) => m (t a)
-> t (n a) -> m (n a)

Without that instance you'd be unable to build matrices with Point's as one
or both of the dimensions, which are intended to transform points.

If we can decide that that doesn't make sense (as after all points aren't
additive), so such matrices _are_ kinda weird, we can remove the instance.

I'm happy to bend the way Point works, as I stick to the projective
machinery almost exclusively, myself.

Thoughts?

-Edward

On Tue, Mar 17, 2015 at 5:47 PM Richard Eisenberg <eir at cis.upenn.edu> wrote:

> Hi café,
>>
>> I'm in the middle of responding to https://github.com/goldfirere/
>> units/pull/45 and trying to learn the `linear` package, which I have yet
>> to use.
>>
>> I have what may be a basic question: why is there an `instance Additive f
>> => Additive (Point f)` (in the Affine module)? It would seem that the whole
>> point of Point is that it is *not* Additive. We don't want to add Points!
>>
>> Could someone enlighten me?
>>
>> Thanks!
>> Richard
>>
>> PS: Of course, this instance is directly hurting my use of the package.
>> But it is hurting my understanding of the package, because it disagrees
>> with the mental model I've built up of the definitions.
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150318/fea164e8/attachment.html>


More information about the Haskell-Cafe mailing list