[Haskell-cafe] vector-space and standard API for vectors
Alexey Khudyakov
alexey.skladnoy at gmail.com
Sun Oct 31 17:59:34 EDT 2010
On Sat, Oct 30, 2010 at 2:07 PM, Henning Thielemann
<schlepptop at henning-thielemann.de> wrote:
> wren ng thornton schrieb:
>> 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)
>
> Looks like you are about to re-implement numeric-prelude. :-)
>
Only limited subset. Very limited. Everything is too big to be implemented
> Vector (Complex a) is a vector with respect to both 'a' and 'Complex a'.
>
It is but it's difficult to encode this. Type class below allows to have
multiple scalars. But then type checker cannot infer type of 2 in expression
`2 *^ vector' and so type signature must be added which is hardly usable
class Module v s where
(*^) :: s -> v -> v
I think one is forced to convert real number to complex or use some
operations specific to data type.
More information about the Haskell-Cafe
mailing list