classes inheritance seems not to work.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

classes inheritance seems not to work.

asker
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
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?
 
Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: classes inheritance seems not to work.

asker
Looks like I finally subscribed to the list, sorry if this message is duplicated:
 
 
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?
 
Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: classes inheritance seems not to work.

Sebastian Sylvan
In reply to this post by asker
On 2/18/06, asker <[hidden email]> 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
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe