
Marcin 'Qrczak' Kowalczyk wrote:
Benjamin Franksen
writes: BTW, isn't Matrix a functor over Num so we can use fmap for lifting? Ah, doesn't work because of the extra Num constraint, grrr...
I see no need of putting the Num constraint on the type definition. fmap will work.
Hmm... It appears I was being dense (or a perfectionist) as I couldn't define a generic instance of Functor for all Matrices generalised over Array type. Of course the solution is just to define an instance for each array type... Here's the latest version ... now smaller with the Floating instance removed, but an instance of Functor added, and a better Show instance (that generates valid Haskell using the constructor functions provided)... Have also removed the Matlab style "scalar" by "matrix" operations, so to multiply a scalar by each element use fmap (or mmap) fmap (+1) matrix I guess in the end it's just more Haskell like - even if it is harder to read than the Matlab code. Keean.