[Haskell-cafe] classes inheritance seems not to work.
Sebastian Sylvan
sebastian.sylvan at gmail.com
Sun Feb 19 12:13:49 EST 2006
On 2/18/06, asker <spamisnothx-askme at yahoo.es> wrote:
>
> Hi,
>
> I'm trying to make three haskell classes and an instance this way:
> ------------------------------------------------------------------------------
> class (Eq a) => Graph a where
> vert :: [a]
> ady :: a -> [a]
>
> class (Graph a) => Paths a where
> gps :: a -> a -> [[a]]
>
> class (Paths a) => Minimum a where
> mgps :: a -> a -> [a]
>
> instance Minimum Char where
> vert = ['a' .. 'f'] -- This is the line of the error message.
> ady 'a' = ['b', 'c']
> ady 'b' = ['d', 'c', 'e']
> ady 'd' = ['f']
> gps = bepgr -- bepgr is defined and implemented in other code's part
> mgps = head gps
> ------------------------------------------------------------------------------
>
>
>
>
> When I try to run this I get: "ERROR: filepath:line -No member vert in class
> "Minimum"" I don't know why does this happen, am I doing something wrong?
>
The class Minimum doesn't have a member 'vert', Graph does, though.
You need to instantiate your data type in all three classes
separately. So three separate "instance" declarations, one for each
class.
--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
More information about the Haskell-Cafe
mailing list