0
getFloat :: IO Float

main = do
 putStr "Enter question number: "
 xs <- getLine
 if (xs == 3)
     then do
      main2
     else 
      main2

main2 = 
pricePizza ::  Double -> Double -> Double
pricePizza x y  = priceBase x  +  priceTopping x y * 1.6 

priceBase x = (3.14 * (x * 0.5) * x) * 0.001
priceTopping x y  = ((3.14 * (x * 0.5) * x) * 0.0002) * y

Why doesn't this work?

2
  • 1
    main2 = on its own is a problem… you have to implement main2. Commented Nov 9, 2015 at 1:11
  • @minitech sorry I should probably edit the question. there is going to be more funtions. so if xs = 3 then go to this function if xs = something else go to that function Commented Nov 9, 2015 at 1:12

1 Answer 1

3

You can't have a line like:

 main2 =

on its own. It's a syntax error.

If you want to have keep some partially defined functions that you are still working on, you can use undefined:

main2 = undefined

or else put in some dummy code:

main2 = 

Once that is fixed, you have two more problems:

  1. You have a type for getFloat, but no definition. If you plan to define it later then you can give it an undefined value, otherwise you should remove it.

  2. The type of xs is String so you can't compare it to 3, which is and Int. You can just use a string literal instead.

I think this is what you were trying to do, and compiles:

main :: IO ()
main = do
 putStr "Enter question number: "
 xs <- getLine
 if (xs == "3")
     then do
      main2
     else
      main2

main2 = putStrLn "main 2"

pricePizza ::  Double -> Double -> Double
pricePizza x y  = priceBase x  +  priceTopping x y * 1.6

priceBase x = (3.14 * (x * 0.5) * x) * 0.001
priceTopping x y  = ((3.14 * (x * 0.5) * x) * 0.0002) * y
Sign up to request clarification or add additional context in comments.

2 Comments

this is exacthly what was needed apart from I need to define main2 to work with pricePizza now and im not too familiar with how to do that.
If you have some problems implementing that part, maybe ask a separate question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.