I am going through Hudak's "Gentle introduction to Haskell". As stated in my earlier questions, I have a little experience with C and C++. So when I came across the term "Constructors" in the introduction to type constructors and data constructors I can't help but wonder if any similarities are there with C++ constructors or is it completely analogous with the later.
So, the first example that Hudak provides is the following:
data Color = Red|Green|Blue
So from the first example I got to know that the RHS is the data constructor. However, here I wasn't clear about type constructors.
In the next example:
data Point a = Pt a a
It has been clearly stated that Point
is the data constructor and Pt
is the type constructor. So what exactly does a constructor do? Is it a function call as it is in case of C++?
How exactly are the work of point and pt differentiated? what is "pt" doing?
Point
is the type constructor andPt
is the data constructor. – melpomene