Haskell Matrix Library...
k.schupke at imperial.ac.uk
Tue Jun 14 09:58:41 EDT 2005
Yes, it should be - I have corrected:
mmap :: (IArray a e, Num e, IArray a e', Num e') => (e -> e') ->
Matrix a e -> Matrix a e'
It still cannot be an instance of functor though as:
instance Functor (Matrix a) where
fmap f = mmap x
We cannot constrain the instance correctly... We need "IArray a e", but
fmap is (expanding)
fmap :: b -> c -> Matrix a b -> Matrix a c
But 'b' and 'c' cannot be constrained by the instance... because they do
not occur in the
class, only the function definition.
Bulat Ziganshin wrote:
>Tuesday, June 14, 2005, 3:54:08 PM, you wrote:
>KS> class Functor m where
>KS> fmap :: a -> b -> m a -> m b
>KS> But the type of "mmap" is
>KS> mmap :: e -> e -> Matrix a i e -> Matrix a i e
>KS> in other words we map values to the same type, not a different type.
>mmap should be
>mmap :: (e -> e1) -> Matrix a i e -> Matrix a i e1
>for example, we can map matrix of strings to matrix of its lengths
More information about the Libraries