Jane Doe
Jane Doe

Reputation: 61

Haskell - Parse error on input '='

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?

Upvotes: 0

Views: 179

Answers (1)

Peter Hall
Peter Hall

Reputation: 58725

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

Upvotes: 3

Related Questions