產生我正在實踐Haskell,我試圖創建電子商店。錯誤:沒有實例(數量價格)從字面
我創建的類型Code
,Name
,Genre
和Price
,元組Movie
和一個元組列表Movies
,當我嘗試在tableMovies
顯示的消息添加的電影:
Prelude> :l movies [1 of 1] Compiling Main (movies.hs, interpreted) movies.hs:11:45: No instance for (Num Price) arising from the literal `50' Possible fix: add an instance declaration for (Num Price) In the expression: 50 In the expression: (1, "Movie 1", "Adventure", 50) In the expression: [(1, "Movie 1", "Adventure", 50), (2, "Movie 2", "Horror", 30)] Failed, modules loaded: none. Prelude>
我的代碼:
type Code = Integer
type Name = String
type Genre = String
data Price = Integer | Float
type Movie = (Code, Name, Genre,Price)
type Movies = [(Movie)]
tableMovies :: Movies
tableMovies = [ (001,"Movie 1", "Adventure",50)
, (002,"Movie 2", "Horror", 30)]
我發現這個問題的一些答案,但我無法理解,因爲代碼對我來說非常複雜。我纔剛剛開始在哈斯克爾