[Haskell-cafe] Newbie Question on type constructors

Brian Beckman bbeckman at exchange.microsoft.com
Fri Oct 29 18:08:34 EDT 2004

This is a tiny question on the "data" syntax. 

Consider the following (cribbed from Paul Hudak's "School of Expression"
book, page 22):
data Shape = Circle Float 
           | Square Float

I read this something along the lines of "'Shape' is a type constructor,
for use in other type-defining expressions, and 'Circle' and 'Sqare' are
its two data constructors, which should be used like functions of type
'Float -> Shape'".  Indeed, typing "Circle" at the Hugs prompt reveals
that Haskell has a "function" named "Circle" with type "Float -> Shape."

However, I don't know of other circumstances where (1) I can declare
functions with capitalized names (Hugs groans about syntax errors if I
attempt the following:

Circle2 :: Float -> Shape
Circle2 =  Circle

And (2) where the argument-types of a function can be declared on the
function's right-hand side. 

So, in some sense, am I right to think of "data" as a special syntax for
special kinds of function declarations, namely data-constructor function
declarations, and that this syntax is different in appearance, but not
terribly different in meaning, from the ordinary syntax, typified by

circle2 :: Float -> Shape
circle2 =  Circle

(this is just the uncialized version of the one above, and is perfectly

Apologies if this is just too nitpicky and pedantic for words, but I try
to notice everything.

More information about the Haskell-Cafe mailing list