
On 3/19/06, Neil Rutland
Hi Everyone,
I am completely new to this so my apologies if some of the questions are ill described/directed, but if they are just let me know and i'll try and make the relevent changes.
I chose this one as it seemed the right sort for me with my (rudimentary knowledge), the first question is probably very simple but a bit of a jump for my brain.
Basically i want to add two user entered numbers together to calculate the number of stops between two traint stations so i think i would define that as so:
stops :: int->int->int
I think that says that the function stops takes two integers and returns an integer.
What i'm not entirely sure of is how i'd then write the function itself because i literally want it to have the following form
stops (x,y) = x+y
I think you're looking for: stops x y = x+y Or use your own definition and change the type to stops:: (Int,Int) -> Int It's generally recommended not to send the parameters of your function as a tuple (like you're doing) but rather "one at a time" like the example I gave above. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862

I think you're looking for:
stops x y = x+y
Or use your own definition and change the type to stops:: (Int,Int) -> Int It's generally recommended not to send the parameters of your function as a tuple (like you're doing) but rather "one at a time" like the example I gave above.
Also, types in Haskell have initial capital letters.
stops :: Int->Int->Int
Try reading the tutorial here if you haven't seen it yet; it's geared toward programmers who know other languages but not Haskell: http://www.isi.edu/~hdaume/htut/ or any of the tutorials listed on this page: http://haskell.org/learning.html and this is a great list of FAQs: http://haskell.org/hawiki/HaskellNewbie Enjoy and welcome! Jared. -- http://www.updike.org/~jared/ reverse ")-:"

Neil Rutland wrote:
stops :: int->int->int
I think that says that the function stops takes two integers and returns an integer.
This is correct (though as someone else pointed out, Haskell types start with a capital letter).
What i'm not entirely sure of is how i'd then write the function itself because i literally want it to have the following form
stops (x,y) = x+y
As "stops" just adds numbers, it is equivalent to the + operator, so you don't have to write a function at all. It doesn't do any harm to write a function, but the simplest way of expressing "stops" is this: stops :: Int -> Int -> Int stops = (+) One of the benefits of a functional language is that you can assign functions as well as data! Pete

Am Sonntag, 19. März 2006 17:45 schrieb Neil Rutland:
<P class=RTE align=left>Cheers everyone - if i have blatantly missused this mailing list just email me some abuse.</P>
I'd just ask you to send your list mails in plain text or at least plain text plus HTML, not in HTML only. Best wishes, Wolfgang
participants (6)
-
Jared Updike
-
Neil Rutland
-
Pete Chown
-
Robin Green
-
Sebastian Sylvan
-
Wolfgang Jeltsch