[Haskell-cafe] Specializing classes with classes

alex maskif at yahoo.com.au
Fri Dec 28 22:53:09 EST 2007

Hi, I am new to everything Haskell and am stumped on
an aspect of Type Classes.

I would like to do this:

    class Foo t where
        hi :: t -> Bool

    class Foo t => Bar t where
        hi x = True
But using GHC 6.8.1 on PPC I get this error:

    `hi' is not a (visible) method of class `Bar'

The actual problem is more like this:

    class Num a => Alg a where
        (<>)    :: Mat m => m -> a -> a    -- matrix

    class Alg v 	=> Vec v where
        toRow, toColumn     :: Mat m => v -> m
        fromRow, fromColumn :: Mat m => m -> v
        fromRow     = fromColumn . transpose
        toRow       = transpose . toColumn
        (<>) m v    = fromColumn (m <> (toColumn v))

    class Alg m     => Mat m where
        transpose   :: m -> m

(I hope that's readable...)

I'm having trouble finding what I need with Google,
and SOE doesn't really go into specifics.

Thanks for any help... Alex

      Make the switch to the world's best email. Get the new Yahoo!7 Mail now. www.yahoo7.com.au/worldsbestemail

More information about the Haskell-Cafe mailing list