am I wording this right?

Is this the right way of saying what I'm trying to say? "Functor is a typeclass of type constructors which take one argument." Thanks, Mike

That sound okay to me.
Usually when we have type constructor "T a" and an "instance Functor T
where..." we just say that "T is a functor"
Note that the signature of a type constructor is called the "kind" of
the type constructor.
For example, the following code
data NotSoKind = X
instance Functor NotSoKind where
would give the error:
Kind mis-match
Expected kind `* -> *', but `NotSoKind' has kind `*'
In the instance declaration for `Functor NotSoKind'
and
instance Functor (,) where
gives the error
(,)' is not applied to enough type arguments
Expected kind `* -> *', but `(,)' has kind `* -> * -> *'
In the instance declaration for `Functor (,)'
Note however that the following is correct:
instance Functor ((,) a) where
fmap f (x,y) = (x, f y)
and even:
instance Functor ((->) a) where
fmap f g = f . g
You can ask GHCi to show the kind of a type constructor:
:kind (,)
(,) :: * -> * -> *
:kind ((,) 1)
((,) 1) :: * -> *
:kind Char
*
On Wed, Aug 5, 2009 at 1:07 AM, Michael P Mossey
Is this the right way of saying what I'm trying to say?
"Functor is a typeclass of type constructors which take one argument."
Thanks, Mike _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Peter Verswyvelen wrote:
Note however that the following is correct:
instance Functor ((,) a) where fmap f (x,y) = (x, f y)
and even:
instance Functor ((->) a) where fmap f g = f . g
Thanks. What's curious to me about these instances is that they have a type variable a which is never referenced in the definition. Is there ever a case in which you would refer to the type variable 'a' somewhere in the definition of an instance? I know that the types of the "member functions" of the instance are given in the class definition, so there is no place to put a type definition in the instance, I don't think. Thanks, Mike

On Wed, Aug 5, 2009 at 2:25 AM, Michael P Mossey
Peter Verswyvelen wrote:
Note however that the following is correct:
instance Functor ((,) a) where fmap f (x,y) = (x, f y)
Thanks. What's curious to me about these instances is that they have a type variable a which is never referenced in the definition.
Is there ever a case in which you would refer to the type variable 'a' somewhere in the definition of an instance? I know that the types of the "member functions" of the instance are given in the class definition, so there is no place to put a type definition in the instance, I don't think.
Good question, I don't know. You can use it to add constraints, e.g. instance Show a => Functor ((,) a) where fmap f (x,y) = (x, f y) but the "a" type does not seem to be available in the definitions, it's scope seems to be limited, e.g. instance Functor ((,) a) where fmap f (x,y) = (x::a, f y) doesn't compile. But I'm just guessing here, don't know the details :-(
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

2009/08/04 Michael P Mossey
Is there ever a case in which you would refer to the type variable 'a' somewhere in the definition of an instance?
When using overloaded functions to write the instance -- for example, `fmap` or `mappend` -- you might place type signatures on them to disambiguate. -- Jason Dusek
participants (3)
-
Jason Dusek
-
Michael P Mossey
-
Peter Verswyvelen