当它可以在 CMD 上运行时,我如何 运行 此功能
How can I run this function when it can work on CMD
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]))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
:重新加载
有没有人告诉我如何解决这个问题,这样这个功能就可以 运行
你的list comprehension不是一个函数,它是一个定义在顶层的表达式,意义不大。您可以定义一个 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 ()
<strong>main = print</strong> [car | (car, n) <- sortBy cmp(zip cars (randoms (mkStdGen 123456) :: [Int]))]
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]))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :重新加载
有没有人告诉我如何解决这个问题,这样这个功能就可以 运行
你的list comprehension不是一个函数,它是一个定义在顶层的表达式,意义不大。您可以定义一个 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 ()
<strong>main = print</strong> [car | (car, n) <- sortBy cmp(zip cars (randoms (mkStdGen 123456) :: [Int]))]