newbie syntax question
Memovich, Gary
GARY.MEMOVICH@kla-tencor.com
Tue, 24 Jul 2001 13:21:35 -0700
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--------------InterScan_NT_MIME_Boundary
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C1147E.3CB3B690"
------_=_NextPart_001_01C1147E.3CB3B690
Content-Type: text/plain;
charset="iso-8859-1"
Actually, all functions in Haskell take only one argument, although the
people writing the program usually don't think of it this way.
scale could alternatively have been defined with type
scale :: (Picture, Int) -> Picture
which looks more like what we would expect in a function of two arguments.
But even here there is actually only a single argument, which happens to be
a pair of values.
The given declaration
scale :: Picture -> Int -> Picture
is written in 'curried' form. This means that scale is a function of one
argument, 'Picture', and that its return value is a new function with type
Int -> Picture. That new function can immediately be applied to an int
value so that it appears as if you called scale with two values instead of
just one.
instead of writing
scale pic 3
for example, you could have written
(scale pic) 3
or even
let x = scale pic in x 3
Which might make it a little easier to see what is actually happening.
Hope this helps,
-- Gary
-----Original Message-----
From: Cagdas Ozgenc [mailto:co19@cornell.edu]
Sent: Tuesday, July 24, 2001 1:07 PM
To: haskell@haskell.org
Subject: newbie syntax question
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
------_=_NextPart_001_01C1147E.3CB3B690
Content-Type: text/html;
charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4522.1800" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2>Actually, all functions in Haskell take only one argument, although the
people writing the program usually don't think of it this
way.</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff size=2>scale
could alternatively have been defined with type</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001> <FONT face=Arial
color=#0000ff size=2>scale :: (Picture, Int) -> Picture</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff size=2>which
looks more like what we would expect in a function of two arguments. But
even here there is actually only a single argument, which happens to be a pair
of values.</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff size=2>The
given declaration</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001> <FONT face=Arial
color=#0000ff size=2>scale :: Picture -> Int ->
Picture</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff size=2>is
written in 'curried' form. This means that scale is a function of
one argument, 'Picture', and that its return value is a new function with
type Int -> Picture. That new function can immediately be applied to an
int value so that it appears as if you called scale with two values instead of
just one.</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2>instead of writing</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001> <FONT face=Arial
color=#0000ff size=2>scale pic 3</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff size=2>for
example, you could have written</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001> <FONT face=Arial
color=#0000ff size=2>(scale pic) 3</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff size=2>or
even</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001> <FONT face=Arial
color=#0000ff size=2>let x = scale pic in x 3</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff size=2>Which
might make it a little easier to see what is actually
happening.</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff size=2>Hope
this helps,</FONT></SPAN></DIV>
<DIV><SPAN class=734081220-24072001><FONT face=Arial color=#0000ff size=2>--
Gary</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Cagdas Ozgenc
[mailto:co19@cornell.edu]<BR><B>Sent:</B> Tuesday, July 24, 2001 1:07
PM<BR><B>To:</B> haskell@haskell.org<BR><B>Subject:</B> newbie syntax
question<BR><BR></FONT></DIV>
<DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>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.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>for example a function declaration is given as
follows</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>scale : : Picture -> Int ->
Picture</FONT></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>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)?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>scale : : Picture , Int ->
Picture</FONT></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Is there a specific reason not to be able to
distinguish the input parameters from the output parameter?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Thanks</FONT></DIV>
<DIV> </DIV></BLOCKQUOTE></BODY></HTML>
------_=_NextPart_001_01C1147E.3CB3B690--
--------------InterScan_NT_MIME_Boundary--