[Haskell-cafe] Problem with type families

Victor Nazarov asviraspossible at gmail.com
Mon Sep 21 17:15:48 EDT 2009


I've tried to reimplement code presented in the following blog post:
http://cdsmith.wordpress.com/2009/09/20/side-computations-via-type-classes/

But I've got stuck with the following error:

Triangulable.hs:41:8:
    `addRows' is not a (visible) method of class `Triangulable'

Triangulable.hs:43:8:
    `addCols' is not a (visible) method of class `Triangulable'

I think the minimal example to reproduce this error is the following:

...
class Triangulable m
  where type Elem m
        (@@)     :: m -> (Int, Int) -> Elem
        size     :: m -> Int
        swapRows :: Int -> Int -> m -> m
        swapCols :: Int -> Int -> m -> m
        addRow   :: (Num Elem) => Elem -> Int -> Int -> m -> m
        addCol   :: (Num Elem) => Elem -> Int -> Int -> m -> m

newtype ListMatrix a = ListMatrix [[a]]

instance Num a => Triangulable (ListMatrix a)
  where type Elem (ListMatrix a) = a
        (ListMatrix xs) @@ (i, j) = xs !! i !! j
        size (ListMatrix xs) = size xs
        swapRows m n (ListMatrix xs) = ListMatrix $ swap m n xs
        swapCols m n (ListMatrix xs) = ListMatrix $ map (swap m n) xs
        addRows q m n (ListMatrix xs) = ListMatrix $ modifyNth n
(zipWith comb (xs !! m))
          where comb a b = q * a + b
        addCols q m n (LisMatrix xs) = ListMatrix $ map (\row ->
modifyNth n (comb (row !! m)) row)
          where comb a b = q * a + b
...

How can I fix this?

--
Victor Nazarov


More information about the Haskell-Cafe mailing list