LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-05-2011, 12:14 AM   #1
hydraMax
Member
 
Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467
Blog Entries: 60

Rep: Reputation: 51
Haskell: Integral Parameter


Noob Haskell question: Let's say that I have a function that calculates the cost of booking airline tickets according to some market-driven formula:

Code:
-- total cost for n numbers of persons traveling together 
cost 0 = 0
cost 1 = 1000
cost n = if n < 0 then error "cost of negative travelers invalid"
         else if n >= 10 then 700 * n
              else 1000 * n - 500
Now, the only thing that seems lacking here is that I know that in /all/ cases, n is going to be a whole number. But how to I specify that?

After some experimentation I discovered that if I passed in a special option to the compiler I could do this:

Code:
cost (n :: Integer) = if n < 0 then error "cost of negative travelers invalid"
         else if n >= 10 then 700 * n
              else 1000 * n - 500
However, I actually want it to be any whole number type (i.e., Int or Integer) so this is not satisfactory.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Integral constant overflow nitin_ucer Programming 5 09-12-2010 11:15 AM
What is integral (x tan(x) dx) corbis_demon Linux - General 1 12-06-2007 05:29 AM
linux bash - how to use a dynamic parameter in shell parameter expansion expression nickleus Linux - General 2 08-21-2006 04:54 AM
help with my C program, switch expression not integral? NetBlaster Programming 2 05-05-2006 02:39 PM
Integral IC chips in inkjet printers xuper Linux - Hardware 3 06-13-2005 01:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration