Why is there a value constructor in addition to the type constructor in Haskell?

后端 未结 3 1030
余生分开走
余生分开走 2021-02-13 06:00

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

3条回答
  •  粉色の甜心
    2021-02-13 06:32

    One convenient way to get the intuition about Types and Values is that the former are compile-time values while the latter are run-time values. In other words, Type constructors are constructors of values in the set of Haskell Types, for the sole aim of typing your program at compile time. That also means you can not construct a type at run-time, and you can not construct a value at compile-time.

    So, because you can not explicitly branch at run-time on the basis of a type value (though you can implicitly with typeclasses), Type constructors are totally useless as run-time objects and in many cases are totally absent in the final binary. Conversely, because values constructors allows to construct values in the set of their type at run-time, they are totally useless as compile-time object.

    Because of this simple property, Type constructors and Value constructors can share names unambiguously.

提交回复
热议问题