I\'m a newcomer to Haskell and am currently going through Real World Haskell. The book says the type constructor is used only in the type signature while the value constructor i
Maybe the names are a little bit misleading. A type constructor represents the name of the type you're declaring. They're called like that because they build types, not values: indeed, being (possibly) parameterized on type variables they define a family of types. They act something like C++'s templates and Java's generics. In data MyType a b = Constr a b
, MyType is a type constructor that takes two types a
and b
to build a new type (MyType a b)
.
A value constructor is the only part you would call a "constructor" in other (object oriented) languages, because you need it in order to build values for that type. So, in the previous example, if you take the value constructor Constr :: a -> b -> MyType a b
, you may build a value Constr "abc" 'd' :: MyType [Char] Char
.