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'm not entirely sure how i need to write that - or even if thats correct, but that looks a bit too C++ for me - could anyone possibly help explain to me the correct way to do it and why (thats my big thing - i don't know why i'm supposed to do these things!!!) Cheers everyone - if i have blatantly missused this mailing list just email me some abuse. Neil _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
On 3/19/06, Neil Rutland <[hidden email]> wrote:
> > > > 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 _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
> 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 ")-:" _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Neil Rutland
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 _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Neil Rutland
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 _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
> > Cheers everyone - if i have blatantly
> > missused this mailing list just email me some abuse. Perhaps you should be asking your teacher this question? I'm sure s/he'd be very happy with you using the list to get other people to do parts of your homework for you. -- Robin _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Free forum by Nabble | Edit this page |