On 23.10.2010 05:11, wren ng thornton wrote:
On 10/22/10 8:46 AM, Alexey Khudyakov wrote:
Hello everyone!

It's well known that Num & Co type classes are not adequate for vectors
(I don't mean arrays). I have an idea how to address this problem.

Conal Elliott wrote very nice set of type classes for vectors.
(Definition below). I used them for some time and quite pleased. Code is
concise and readable.

> class AdditiveGroup v where
> zeroV :: v
> (^+^) :: v -> v -> v
> negateV :: v -> v
[...]
I'd like to know opinion of haskellers on this and specifically opinion
of Conal Eliott as author and maintainer (I CC'ed him)

Just my standard complaint: lack of support for semirings, modules, and
other simple/general structures. How come everyone's in such a hurry to
run off towards Euclidean spaces et al.?

They give familiar warm fuzzy feeling. It's same as monads and applicative functors (-:

I'd rather see,

class Additive v where -- or AdditiveMonoid, if preferred
  zeroV :: v
  (^+^) :: v -> v -> v

class Additive v => AdditiveGroup v where
  negateV :: v -> v

Seems good for me. One more instance declaration to write and no changes in usage.

However when written this way it becomes obvious that
`zeroV' == `mempty' and ^+^ = mappend. Is Additive really needed then?

type family Scalar :: * -> *

class Additive v => LeftModule v where
  (*^) :: Scalar v -> v -> v

class Additive v => RightModule v where
  (^*) :: v -> Scalar v -> v

Could you give some example of data type for which (*^) ≠ flip (^*)?
I couldn't imagine one.

...

Though I don't know how much that'd affect the niceness properties you
mentioned.


_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to