Question on constructor/type classes 
Author Message
 Question on constructor/type classes

Hello,

I have the following problem of which I think the answer is quite simple,
but of which I don't seem to be able to find the correct solution.

I have the following two data types

        data N a = On a | Drie (N a) (N a) (N a)        ,
        data Q a = Oq a | Twee (N (Q a)) (N (Q a))      .

I also have

        class Functor f where
                map' :: (a -> b) -> (f a -> f b)

and

        instance Functor f where
                map' f (On x) = On (f x)
                map' f (Drie x y z) = Drie (map' f x) (map' f y) (map' f z)

My question now is how to get a similar instance on data type Q.

I tried:

        instance Functor f where
                map' f (Oq x) = f x
                map' f (Twee x y) = Twee (map' f x) (map' f y)

but this (of course) results in an error.
I know why I get the error, but I don't seem to find a way around it.

If you know what I am doing wrong and you know a solution I would
appreciate it very much if you could send me any comments and solutions.

Thank you very much in advance,

 Harold Weffers      c/o Eindhoven University of Technology
                         Department of Mathematics and Computing Science
     /_/  /   /          HG 6.64
    / /. /_/_/.          P.O. Box 513, 5600 MB  EINDHOVEN, The Netherlands
                         Telephone: (+31) (0)40 - 474231


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
| Disclaimer: I say what?  |      - To err is human, to forgive divine -  |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#



Sat, 23 Dec 1995 19:32:48 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Re : Question on constructor/type classes

2. New User Question: extension types and python 2.2/class/type

3. LSP and constructors with first-class classes

4. Very basic questions about class ARRAY and FILE-types

5. Haskell - Question about multi-parameter type classes

6. Primitive type constructors

7. type constructor would escape its scope

8. A Type Class Question

9. enhancing dictionary update method and the dict type constructor

10. Really stupid question regarding PEP 252 and type/class unification

11. Grok (was: Re: Really stupid question regarding PEP 252 and type/class unification)

12. Overloading TYPE constructor

 

 
Powered by phpBB® Forum Software