[Haskell-beginners] (no subject)

Kim-Ee Yeoh ky3 at atamo.com
Thu Mar 28 21:30:57 CET 2013


On Fri, Mar 29, 2013 at 2:22 AM, Jamie F Olson <jamie.f.olson at gmail.com> wrote:
> None of the tutorials/manuals were entirely clear to
> me, nor was the wiki(http://www.haskell.org/haskellwiki/Constructor),
> which uses the same statement as the example of both type
> and data constructors.

Indeed, it's a very common gotcha:

JSObject is a type constructor in the sense that it takes a type and
returns a type.

It so happens that JSObject is also a data constructor that takes a
value and returns another value of the datatype of which it is a
constructor.

Why is this ambiguity allowed?

Because JSObject as type constructor can't be used at the term level.
You can only write type signatures with it, you can't use it in an
expression.

JSObject as data constructor is the reverse. It's a function like any
other. In this case, it has type signature JSObject :: JSObject
JSValue -> JSValue. Note how JSObject after the double colon is
JSObject as the one-parameter type constructor (see newtype
definition).

Confusing, eh?

After a bit of practice, it should be clear that this is a means of
conserving the namespace. You can always start with a different naming
convention on your own code until you get used to the separation
between types and terms (which does tend to become muddled as
dependent types loom, but that's a story for later).

-- Kim-Ee



More information about the Beginners mailing list