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
this should be on a list of the 10 first questions someone will ask when learning haskell. I have introduced several friends to the language and they all seem to ask the same things, if not always in the same order.. whats the deal with Int -> Int -> Int ... (currying) what does $ mean? is it 'special' syntax? (no, just a $ b = a b) why can't "a <- getChar" be "a = getChar" in a do expression? how do I convert an IO a to just an a? (unsafePerformIO, but that is the wrong answer to the wrong question) general confusion about namespaces, the difference between (a,b) the type and (a,b) the value for instance. how to write some basic idioms only used in an imperitive setting, incrementing a counter, processing input, maintaining state with variables which don't directly translate to haskell usually leading to some confusion when you try to explain why they need to restructure their program. and on a more abstract level, the view of 'do' as a hack for IO rather than monads as an independant and useful abstraction. (i find the Maybe monad one of the better ways to introduce people to non-IO monads, especially if they are used to Maybe in non-monadic usage.) I have some email exchanges somewhere where I explained some of these concepts, perhaps I will edit them and add them to the Wiki, or better yet, find the best explanations from the list and add them... and of course any other newbie questions other people find they encounter... this is somewhat odd ground, because when helping someone learn the language, I WANT people to come to these questions on their own and ask them since it means they are thinking and noticing the places where they need to readjust, so its maybe not a newbies FAQ, for someone evaluating whether to learn the language, but more of a two weeks in and not quite getting everything FAQ. John -- --------------------------------------------------------------------------- John Meacham - California Institute of Technology, Alum. - john@repetae.net ---------------------------------------------------------------------------
participants (2)
-
John Meacham -
Memovich, Gary