하스켈을 praticing하고 있습니다. 전자 영화 상점을 만들려고합니다. 오류 : 리터럴에서 발생하는 (Num Price) 인스턴스가 없습니다.
나는 유형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)]
을
이 문제에 대한 답변을 찾았지만 코드가 매우 복잡하기 때문에 이해할 수 없었습니다. 유형 Price
및 상수 Integer
및 Float
: 만이 줄은 세 가지를 생성 하스켈