-1

I'm trying a program from this tutorial. The program goes like this:

type Name = String
type PriceInCents = Int
type ShoppingListItem = (Name, PriceInCents)
type ShoppingList = [ShoppingListItem]

shoppingList :: ShoppingList
shoppingList = [ ("Bananas", 300)
               , ("Chocolate", 250)
               , ("Milk", 300)
               , ("Apples", 450)
               ]

sumShoppingList :: ShoppingList -> PriceInCents
sumShoppingList []     = 0
sumShoppingList (x:xs) = getPriceFromItem x 
                         + sumShoppingList xs


getPriceFromItem :: ShoppingListItem -> PriceInCents
getPriceFromItem (_, price) = price

main :: IO ()
main = putStrLn ("Price of shopping list is " 
                ++ show (sumShoppingList shoppingList)
                ++ " cents.")

I tried running it and there were no errors but I don't know what to input. I tried but I guess I got it wrong since I got this error:

ERROR - Undefined data constructor

Can anyone tell me what I should input?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mel
  • 111
  • 1
  • 12
  • so maybe what I asked was wrong? i can't explain it well in english but when I run the program, what should I type to make it do its thing? Idk if I'm making sense – Mel Sep 08 '17 at 15:18
  • 2
    Can you describe exactly how you got that error? Your code as it is compiles and produces the right output when run (either by compiling to an executable or by loading the file into `GHCi` then invoking `main`). – hnefatl Sep 08 '17 at 15:19

1 Answers1

5

The program, as it's written, doesn't take any input. Compiling with ghc will produce a working executable. Alternatively, running with runhaskell should work just as well.

I suspect, based on your question, that you're running inside the ghci interpreter. In this case, you can load a file using :l filename.hs (or :r to reload) and then run your main function by simply invoking main.

Silvio Mayolo
  • 62,821
  • 6
  • 74
  • 116