Could not deduce (Ord a) arising from a use of `<' from the context (Eq a) bound by the type signature for shortest :: Eq a => [[a]] -> [a] at code.hs:(8,1)-(9,71) Possible fix: add (Ord a) to the context of the type signature for shortest :: Eq a => [[a]] -> [a] In the expression: sum x < sum (shortest xs) In the expression: if sum x < sum (shortest xs) then x else shortest xs In an equation for `shortest': shortest (x : xs) = if sum x < sum (shortest xs) then x else shortest xs
하지 않는 이유는 함수의 유형 체킹?
'최단'은 실제로이 이름이 맞지 않습니까? -'Data.List'와'Data.Function'의 고차 함수를 사용하여'minimumBy (compare \'on \'sum)'을 사용해보십시오. – leftaroundabout
이 문제를 이해하려면 모든 번호를 주문할 수있는 것은 아님을 아는 것이 중요합니다. 예를 들어, '1 + 2i'와 같은 복소수를 고려해보십시오. 그 (것)들을 주문하는 표준 방법이 없다. – dflemstr
@leftaroundabout은 이미 라이브러리 함수를 사용하여 솔루션을 제안했습니다. 그러나 운동으로 처음부터 그것을 쓰고 싶다면 형식 시그니처 문제를 해결하는 것 외에'가장 짧은 []'의 값을 고려해야합니다. 다시 말하면 재귀의 기초가되어야합니다 (힌트 : 빈리스트에는'minimum'과'maximum'이 정의되어 있지 않습니다.) –