Haskell 输入应如何进入ghci解释器内部?

Haskell 输入应如何进入ghci解释器内部?,haskell,ghci,Haskell,Ghci,我正在尝试一个来自的程序。程序如下所示: type Name = String type PriceInCents = Int type ShoppingListItem = (Name, PriceInCents) type ShoppingList = [ShoppingListItem] shoppingList :: ShoppingList shoppingList = [ ("Bananas", 300) , ("Chocolate", 250)

我正在尝试一个来自的程序。程序如下所示:

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.")
我试着运行它,没有错误,但我不知道输入什么。我试过了,但我想我弄错了,因为我犯了这个错误:

错误-未定义的数据构造函数


有人能告诉我应该输入什么吗?

这个程序在编写时不接受任何输入。使用
ghc
进行编译将生成一个可执行文件。或者,使用
runhaskell
运行也可以


根据你的问题,我怀疑你正在
ghci
解释器中运行。在这种情况下,您可以使用
:l filename.hs
(或
:r
重新加载)加载一个文件,然后通过调用
main

运行主函数,所以我问的可能是错的?我不能用英语很好地解释它,但是当我运行这个程序时,我应该键入什么来让它完成它的任务呢?Idk如果我说得有道理,你能准确描述一下你是如何得到这个错误的吗?您的代码在运行时编译并生成正确的输出(编译为可执行文件或将文件加载到
GHCi
中,然后调用
main
)。噢!谢谢是的这就是我的意思。非常感谢你!