我试图在Int中读取然后在纯函数中使用读取值,但它似乎无法正常工作.在搜索了大量资源后,我使用了从这里开始.
所以我的代码如下:
main = do
putStrLn "Please input a number."
inputjar <- getLine
return (read inputjar :: Int)
Run Code Online (Sandbox Code Playgroud)
哪个工作正常,但当我想在我的纯函数中使用它时:
usrSetBrick :: [[Int]] -> [[Int]]
usrSetBrick xs = setBrick (main) (main) (main) xs
Run Code Online (Sandbox Code Playgroud)
我收到编译错误:
Couldn't match expected type `Int' with actual type `IO Int'
In the first argument of `setBrick', namely `(main)'
In the expression: setBrick (main) (main) (main) xs
In an equation for `usrSetBrick':
usrSetBrick xs = setBrick (tull) (tull) (tull) xs
Failed, modules loaded: none.
Run Code Online (Sandbox Code Playgroud)
所以根据我的理解,main返回一个int.即使它应该,因为我可以从
return中理解(读取inputjar …