module Examples where
import System.Random
import Data.List
cars = ["Ferrari", "Audi", "Honda","McLaren","Merc"]
cmp (x1,y1) (x2,y2) = compare y1 y2
[car | (car, n) <- sortBy cmp(zip cars (randoms (mkStdGen 123456) :: [Int]))]
我不斷收到此錯誤:
決議錯誤:需要模塊頭、匯入宣告或頂級宣告。| 7 | [汽車| (car, n) <- sortBy cmp(zip cars (randoms (mkStdGen 123456) :: [Int]))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ :reload
有沒有人有任何想法讓我解決這個問題,以便此功能可以運行
uj5u.com熱心網友回復:
你的串列理解不是一個函式,它是一個定義在頂層的運算式,沒有多大意義。您可以定義一個main列印結果的,例如:
module Examples where
import System.Random
import Data.List
cars :: [String]
cars = ["Ferrari", "Audi", "Honda","McLaren","Merc"]
cmp :: Ord b => (a, b) -> (a, b) -> Ordering
cmp (x1,y1) (x2,y2) = compare y1 y2
main :: IO ()
main = print [car | (car, n) <- sortBy cmp(zip cars (randoms (mkStdGen 123456) :: [Int]))]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/342910.html
上一篇:當沒有視窗處于活動狀態時如何創建背景關系相關的熱鍵?
下一篇:如何捕獲實體化特定類的所有例外?
