On Tue, Sep 22, 2009 at 1:31 AM, Daniel Fischer <daniel.is.fisc...@web.de> wrote: > Am Montag 21 September 2009 23:15:48 schrieb Victor Nazarov: >> 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? > > Shouldn't the methods be called the same in the class definition and instance > declaration? > > So > > instance ... > where > ... > addRow q m n (ListMatrix xs) = ... > addCol q m n (ListMatrix xs) = .. >
Yes that's right. My fault, I was too conserned with Fractional context in addRow and addCol function that I failed to see a simple bug. Here is working code for those who is interested: http://www.hpaste.org/fastcgi/hpaste.fcgi/view?id=9676#a9676 -- Victor Nazarov _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe