我发现添加类型提示对调试很有用,但我不知道如何使用<-on和IO操作的结果
action :: IO ()
foo :: String --doesnt't compile
foo <- getLine
Run Code Online (Sandbox Code Playgroud)
sha*_*haf 11
你不能这样做,因为< - 不是声明.你可以:
action :: IO ()
action = do
foo <- getLine :: IO String
...
Run Code Online (Sandbox Code Playgroud)
或者,用{-# LANGUAGE ScopedTypeVariables #-}:
action :: IO ()
action = do
foo :: String <- getLine
...
Run Code Online (Sandbox Code Playgroud)