[Haskell-beginners] Type declarations

Francesco Ariis fa-ml at ariis.it
Sun Nov 26 14:07:36 UTC 2017


On Sun, Nov 26, 2017 at 02:50:30PM +0100, Patrik Iselind wrote:
> Hi,
> 
> What's the difference between `delta :: (Point t) => t -> t -> Double` and
> `delta :: Point p -> Point q -> Double`. The later one is accepted by GHCI
> when i do :load.

Hello Patrik,
    `delta :: (Point t) => t -> t -> Double` means Point is a typeclass
and t is an instance of a typeclass.
In your case point is a datatype (data Point a etc. etc.) so the second
signature is the correct one.

> In the second version, which is accepted by GHCI, i don't see the point of p
> and q. Can i use these somehow?

`p` and `q` are the parameter of `Point a`, but since the definition
of Point is:

    data Point a = Coordinate Double Double
                 deriving (Show)

that `a` most likely has... no point (ueueuee pardon the pun) and would
better be written as

    data Point = Coordinate Double Double
                 deriving (Show)

Does this make sense?


More information about the Beginners mailing list