[Haskell-cafe] class and instance

Daniel Schoepe daniel.schoepe at googlemail.com
Sun Jul 10 13:20:14 CEST 2011


On Sun, 10 Jul 2011 11:49:44 +0100, Patrick Browne <patrick.browne at dit.ie> wrote:
> My main question is in understanding the relationship between the
> arguments of the functions getX and getY in the class and in the
> instance. It seems to me that the constructor Pt 1 2 produces one
> element of type Point which has two components. How does this square
> with the class definition of getX which has two arguments?
> Is there a difference between:
> getX :: p a -> a

This applies the type constructor p, in this case Point to the type
variable a. It is not a function that takes two arguments.

A minor clarification: Pt 1 2 produces a value of type "(Num a) => Point
a", so a type where the type constructor Point is already applied to
something. Just "Point" is not a valid type a value can have, but
something that you have to apply to another type, called a type
constructor.

>  and
> getX :: p -> a -> a

This is a function that takes two arguments.

Cheers,
Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110710/c3e0edd3/attachment.pgp>


More information about the Haskell-Cafe mailing list