[Haskell-beginners] Type declarations

mrx patrik.mrx at gmail.com
Sun Nov 26 18:02:36 UTC 2017


Den 26 nov 2017 15:08 skrev "Francesco Ariis" <fa-ml at ariis.it>:

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`,


What do you mean by 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?


I think I'll have to chew that until I reach the chapter on type classes in
real world haskell. Hopefully I'll get it then.

Do you think it would be a mistake to simply skip writing the type
declarations completely until I've reached type classes?

// Patrik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171126/e57105aa/attachment.html>


More information about the Beginners mailing list