newbie syntax question

Hamilton Richards
Tue, 24 Jul 2001 15:42:28 -0500

At 3:07 PM -0500 7/24/01, Cagdas Ozgenc wrote:
>    Hi,   I am extremely new to Haskell. This will be my  first question,
> so go easy. I have just read Chapter 1 on Simon Thompson's  book.  
> for example a function declaration is given as  follows
>   scale : : Picture -> Int ->  Picture
> If the first two types are input variables why does  the syntax
> require me to use arrows twice? I mean isn't the following syntax
>  more readable (hypothetically)?  
> scale : : Picture , Int -> Picture
> Is there a specific reason not to be able to  distinguish the
> input parameters from the output parameter?   Thanks  

Welcome to Haskell! May you find it as rewarding as I have.

As you read further, you'll find that Haskell allows functions to be
applied to less than their full complement of arguments. For example, if
pict :: Picture, then

	scale pict

is a function which, applied to an Int, produces a Picture. That is,

	scale pict :: Int -> Picture

This feature, known as "Currying", is very useful for making rather general
functions which can be specialized by supplying some of their arguments.

The type notation has been designed to accommodate Currying in two ways:

  0. each parameter type is followed by an arrow

  1. the arrow has been designed to be right-associative.

The arrow's right-associativity means that these two types are identical:

	scale : : Picture -> Int ->  Picture

	scale : : Picture -> (Int ->  Picture)

That is, you are free to think of scale as either of

	a function of two arguments which returns a Picture

	a function of one argument which returns (a function of
	one argument which returns a Picture)

That equivalence would be a bit less clear using the comma syntax you suggest.



Hamilton Richards, PhD           Department of Computer Sciences
Senior Lecturer                  Mail Code C0500
512-471-9525                     The University of Texas at Austin
Taylor Hall 5.138                Austin, Texas 78712-1188