[Haskell-beginners] am I wording this right?

Peter Verswyvelen bugfact at gmail.com
Tue Aug 4 20:39:07 EDT 2009


On Wed, Aug 5, 2009 at 2:25 AM, Michael P Mossey<mpm at alumni.caltech.edu> wrote:
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>


More information about the Beginners mailing list