
On Wed, Mar 02, 2011 at 10:04:38AM -0500, Patrick Lynch wrote:
Daniel, Thank you...I understand now... Good day
Ps I think my problem that I'm facing is that I don't see how the instance Functor Maybe is derived from the class Functor...
for example, the author Miran Lipovaca gives the following: class Functor f where fmap::(a->b)->f a->f b
if Maybe replaces f: fmap::(a->b)->Maybe a->Maybe b
Right.
I don't see how the instance Functor Maybe is derived [presumably: 'f' is function (a->b) and not functor 'f' as shown in the class description):
Yes, here 'f' is a function (a -> b). It is confusing that often the letter f is used both to represent an arbitrary Functor or to represent an arbitrary function. But you can tell the difference by seeing whether the f occurs in a type or in some code.
instance Functor Maybe where fmap f (Just x) = Just (f x) fmap f Nothing = Nothing
So you are confused about this code? Can you be more specific what you are confused about? Try thinking carefully about all the types involved. What is the type of f? (You already answered this: a -> b.) What is the type of (Just x)? The type of x? What type is required on the right hand side of the = ? And so on. -Brent