samedi 7 novembre 2015

Haskell - Main function for calling all other functions using user input

I'm new to Haskell and finding it all a bit confusing since coming from Java.

I am trying to implement a function that prompts the user in command line for a number input and then execute the function correlating to the input, or default to the first function if no input is entered.

I'm having a problem with the if function, the compiler keeps giving me errors and I'm not sure why.

main = do 
    putStr "Enter question number: "
    xs <- getLine
        if (xs == "3")
            then
                putStr "number of toppings: "
                top <- getLine
                putStr "diameter of pizza in cm2: "
                size <- getLine
                (pizzaPrice (top size))
            else 
                putStr "Enter 3 numbers: "
                args <- getLine
                (numAbove1 (args))

I'm getting the compiler error "parse error on input ‘if’".

Can someone please explain to me what I am doing wrong.

Aucun commentaire:

Enregistrer un commentaire