我尝试使用CmdArgs从命令行参数中提取整数: ./prg --byte = 512
以下代码无法编译,编译器说Couldn't match expected type `Int' with actual type `Strlen -> Int'
。现在,我以为我认为字节是一个整数?不是吗?
{-# LANGUAGE DeriveDataTypeable #-}
import System.Console.CmdArgs
data Strlen = Strlen {byte :: Int} deriving (Data, Typeable)
strlen = cmdArgsMode $ Strlen {byte = def}
main = do
n <- cmdArgsRun strlen
let datastring = take byte $ randomRs ('a','Z') (mkStdGen 3)
答案 0 :(得分:4)
要从byte
中选择n
字段,您需要说byte n
。所以
let datastring = take (byte n) $ randomRs ('a','Z') (mkStdGen 3)